Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack Special Offer!


Share this page

Follow us
LinkedIn Blogspot Twitter Facebook

Related products
Ultimate Pack  hot!
iGrid Plotter  new!
Image Editor
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
Print Suite .NET
Gradient Controls .NET  new!

Related links
Win32.hlp online version
MegaDetailed.NET
Delphi to C#

Special
Free Software Promotion
Offers for Resellers

Hobby projects
cdtrrracks.com
books.storrre.com
in3steps.com
sovietphillumeny.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