Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack - special offer!

Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

WinAPI Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
cdtrrracks.com new!

Blogspot  greatis.blogspot.com

Search record in TQuery - Databases - Tips & Tricks - Greatis Delphi Pages

Use something like example below, but it could use some exception handling.
Call DisableControls before iterating through a large number of records in the dataset to prevent data-aware controls from updating every time the active record changes.
Disabling controls prevents flicker and increases speed because data does not need to be written to the display.


procedure TForm1.Button1Click(Sender: TObject);
var
  StringToFind: string;
  CurrentPos: TBookmark;
  Found: Boolean;
begin
  StringToFind:=Edit1.Text;
  if Form1.Query1.State=dsEdit then 
    Form1.Query1.Post;
  if StringToFind='' then 
    Exit;
  with Form1 do
  begin
    CurrentPos:=Query1.GetBookmark;
    Query1.DisableControls;
    Found:=False;
    Query1.Next;
    while (not Query1.EOF) and (not Found) do
    begin
      if Query1.Fields[1].AsString=StringToFind then 
        Found:=True;
      if not Found then 
        Query1.Next;
    end;
    if not Found then
    begin
      MessageDlg(
        'No more matching members found.', 
        mtInformation, 
        [mbOK], 
        0);
      Query1.GotoBookmark(CurrentPos);
    end;
    Query1.EnableControls;
    Query1.FreeBookmark(CurrentPos);
  end;
end;
For more
Delphi Help

Download source