Mirror

Accelerate database searches (Views: 711)


Problem/Question/Abstract:

How to accelerate database searches

Answer:

Do you want a simple, one-line method for speeding up your database searches? After you know what your search target is but before beginning your search, disable the search table with the DisableControls method. This effectively disconnects the DataSet from the DataSource component. For example:

unit Unit1;

type
  TForm1 = class(TForm)
    DataSource1: TDataSource;
    Table1: TTable;
    Button1: TButton;

    procedure TForm1.Button1Click(Sender: TObject);
  var
    SeekValue: string;
    begin
      Table1.DisableControls;
      Table1.FindKey([SeekValue]);
      Table1.EnableConstraints;
    end;

  end.

As the search advances through an index, using the Next method, data aware components attached to the dataset are updated. The speed increase results from severing the connection, avoiding the component updates and restoring the connection when the search is completed.

<< Back to main page