2010. szeptember 7., kedd

How to enhance TDBGrid performance in a slow ODBC connection


Problem/Question/Abstract:

I am using a TDBGrid through a slow ODBC connection to the data. When I scroll the grid it changes the selected row and takes an age to update all the "detail" queries run off it. The time it takes to update the "detail" queries wouldn't be a problem if I could scroll the grid and then select a new row once the one I want was in view. Any ideas?

Answer:

Don't use automatic linking, because it re-executes detail queries on every datachange. Instead, use manual linking with timer:


procedure Datasource1Datachange(...)
begin
  Timer1.Enabled := false;
  Timer1.Enabled := true;
end;


procedure Timer1Timer(..);
begin
  {details will be refreshed only when timer expires}
  DetailQ.Params[0].AsInteger := MasterQLinkField.AsInteger;
  DetailQ.Close;
  DetailQ.Open;
end;


I use timer interval from 300 - 500 ms. With this small trick you'll see a real performance boost.

Nincsenek megjegyzések:

Megjegyzés küldése