procedure TtfSearch.InitGrid;
var
i : integer;
begin
tfSearchResults.searchgrid.ColCount:=dmMain.TSearch.FieldCount;
for i:= 0
to dmMain.TSearch.FieldCount -1
do
tfSearchResults.searchgrid.Cells[i,0]:=dmMain.TSearch.Fields.Fields[i].FieldName;
tfSearchResults.searchgrid.RowCount:=2;
end;
{------------------------------------------------------------------------------}
procedure TtfSearch.AddFound(f : TFields);
var
i : integer;
begin
with tfSearchResults.searchgrid
do
begin
for i:= 0
to dmMain.TSearch.FieldCount -1
do
Cells[i,RowCount-1]:=dmMain.TSearch.Fields.Fields[i].AsString;
RowCount:=RowCount+1;
end;
end;
{------------------------------------------------------------------------------}
function GetMemo(tblName, fldName, keyName:
string; keyValue: variant):
string;
const
SELECT = '
SELECT %s FROM %s WHERE %s = :key';
var
ss: TStringStream;
q: TQuery;
begin
q := TQuery.Create(
nil);
with q
do
begin
DatabaseName := '
Mailingliste';
SQL.Text := Format(SELECT, [fldName, tblName, keyName]);
Params.ParamValues['
key'] := keyValue;
Open;
ss := TStringStream.Create('
');
TBlobField(Fields[0]).SaveToStream(ss);
Result := ss.DataString;
ss.Free;
Close;
end;
end;
{------------------------------------------------------------------------------}
procedure TtfSearch.Suche(SearchPart :
string; Feld :
string; GrossKlein : boolean;Komplett : boolean);
var
temp :
string;
RecAll,i : integer;
f: TField;
s, pkName:
string;
pkValue: variant;
begin
with dmMain.TSearch
do
begin
Open;
pkName := '
Nummer';
InitGrid;
First;
while not eof
do
begin
pkValue := FieldValues[pkName];
for i := 0
to Pred(FieldCount)
do
begin
f := Fields.Fields[i];
case f.DataType
of
ftMemo: s := GetMemo('
"'+TableName+'
"', f.FieldName, pkName, pkValue);
else s := f.AsString;
end;
if AnsiContainsText(s, tfSearch.SearchString)
then
begin
AddFound(Fields);
ShowMessage(Fields.Fields[0].asstring);
Break;
end;
end;
Next;
end;
if RecordCount > 0
then
tfSearchResults.tsbStatus.Panels.Items[1].Text:=Format('
%7d/%-7d Treffer gesamt',[RecordCount,RecAll])
else MessageDlg('
Es wurden keine Übereinstimmungen gefunden',mtConfirmation,[mbOK],0);
end;
end;