Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
Hot Offer
Save your money!
Featured
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

News Tips .NET Software VCL Software Partners  

Search record in TQuery
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


Our Partner
DevArchive.com
Recommended
just4fun
Useful Resources
Win32.hlp Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
Newsletters
Subscribe to our news!    Subscribe to our news!


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software