unit usuche;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XPMenu, Grids, DBGrids,
DB, DBTables;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
DataSource1: TDataSource;
Query1: TQuery;
DBGrid1: TDBGrid;
XPMenu1: TXPMenu;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
xStr, xWord, xWhere: String;
xPos: Integer;
begin
if Edit1.Text = '' then
ShowMessage('Bitte Suchbegriff eingeben!')
else begin
xWhere := '';
xStr := Trim(Edit1.Text);
while xStr <> '' do
begin
xPos := Pos(' ', xStr);
if xPos > 0 then
begin
xWord := Trim(Copy(xStr, 1, xPos));
if xWord <> '' then
begin
if xWhere <> '' then
xWhere := xWhere +' AND Titel LIKE "%'+ xWord + '%"'
else
xWhere := ' Titel LIKE "%'+ xWord + '%"';
end;
Delete(xStr, 1, xPos);
xStr := Trim(xStr);
end
else
if xStr <> '' then
begin
if xWhere <> '' then
xWhere := xWhere +' AND Titel LIKE "%'+ xWord + '%"'
else
xWhere := ' Titel LIKE "%'+ xWord + '%"';
xStr := '';
end;
end;
if xWhere <> '' then
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Text := 'SELECT * FROM buecher WHERE '+xWhere;
Query1.Open;
end;
end;
end;
end.