foure
asked on
Search in a TDBGRID
How can I make a search in a TDBGRID ?
here is a code snipit that I used to search a DBMemo maybe it will help you out
add a finddialog to your form...asign it to the onfind event ....
procedure TMainForm.FindDialog1Find( Sender: TObject);
var Buff, B, F : PChar;
BuffL : Word;
begin
With Sender as TFindDialog do
begin
GetMem(F, Length(FindText) + 1);
StrPCopy(F, FindText);
BuffLen:= DBMemo1.GetTextLen + 1;
GetMem(Buff,BuffL);
DBMemo1.GetTextBuf(Buff,Bu ffL);
B:= Buff + DBMemo1.SelStart + DBMemo1.SelLength;
B:= StrPos(B, F);
if B = NIL then MessageBeep(0)
else
begin
DBMemo1.SelStart:= B - Buff;
DBMemo1.SelLength:= Length(FindText);
end;
FreeMem(FT, Length(FindText) + 1);
FreeMem(Buff,BuffL);
end;
end;
To highlight the found text:
begin
DBMemo1.SelStart:= B - Buff;
DBMemo1.SelLength:= Length(FindText);
end;
FreeMem(F, Length(FindText) + 1);
FreeMem(Buff,BuffL);
DBMemo1.SetFocus;
end;
If this helps let me know
Later
BoRiS
add a finddialog to your form...asign it to the onfind event ....
procedure TMainForm.FindDialog1Find(
var Buff, B, F : PChar;
BuffL : Word;
begin
With Sender as TFindDialog do
begin
GetMem(F, Length(FindText) + 1);
StrPCopy(F, FindText);
BuffLen:= DBMemo1.GetTextLen + 1;
GetMem(Buff,BuffL);
DBMemo1.GetTextBuf(Buff,Bu
B:= Buff + DBMemo1.SelStart + DBMemo1.SelLength;
B:= StrPos(B, F);
if B = NIL then MessageBeep(0)
else
begin
DBMemo1.SelStart:= B - Buff;
DBMemo1.SelLength:= Length(FindText);
end;
FreeMem(FT, Length(FindText) + 1);
FreeMem(Buff,BuffL);
end;
end;
To highlight the found text:
begin
DBMemo1.SelStart:= B - Buff;
DBMemo1.SelLength:= Length(FindText);
end;
FreeMem(F, Length(FindText) + 1);
FreeMem(Buff,BuffL);
DBMemo1.SetFocus;
end;
If this helps let me know
Later
BoRiS
Hi,
? Why not just searching the underlying dataset?
regards, ZIf.
? Why not just searching the underlying dataset?
regards, ZIf.
Search in Delphi help on FindKey and Locate methods of TTable.
-this will be helpful.
-this will be helpful.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
add a finddialog to your form...asign it to the onfind event ....
procedure TMainForm.FindDialog1Find(
var Buff, B, F : PChar;
BuffL : Word;
begin
With Sender as TFindDialog do
begin
GetMem(F, Length(FindText) + 1);
StrPCopy(F, FindText);
BuffLen:= DBMemo1.GetTextLen + 1;
GetMem(Buff,BuffL);
DBMemo1.GetTextBuf(Buff,Bu
B:= Buff + DBMemo1.SelStart + DBMemo1.SelLength;
B:= StrPos(B, F);
if B = NIL then MessageBeep(0)
else
begin
DBMemo1.SelStart:= B - Buff;
DBMemo1.SelLength:= Length(FindText);
end;
FreeMem(FT, Length(FindText) + 1);
FreeMem(Buff,BuffL);
end;
end;
To highlight the found text:
begin
DBMemo1.SelStart:= B - Buff;
DBMemo1.SelLength:= Length(FindText);
end;
FreeMem(F, Length(FindText) + 1);
FreeMem(Buff,BuffL);
DBMemo1.SetFocus;
end;
If this helps let me know
Later
BoRiS