Howto : *FAST* browsing through master-detail queries 
Author Message
 Howto : *FAST* browsing through master-detail queries

When browsing through the master records of a  master-detail
query, it can be very annoying that you always have to wait for the
fetching of the visible detail records associated with each master
record.

I have devised a very simple technique that allows you to delay
fetching the detail records, until the user stops browsing the master
query.
This allows me to browse the master table at the speed of the keyboard
repeat rate in a client-server situation (the data is in Informix
Online on unix).

I first tried a method based on a windows message proc that did
the update, but the windows message queue somehow
did not allow me to peek ahead for my own messages
(don't know why).  

The method that works is based on a timer, and goes likes this :

1. do your detail query synchronization manually, by triggering the

    query in the master_datasource_datachange event.
    (the method does not work if you let delphi handle the
    master-detail synchronization).

2. instead of firing the detail query, first disable, then reenable
    a timer with an interval of about 100 msecs.

3. in the timer_timer event, disable the timer, and fire the detail
    query.

If the keyboard/mouse events arrive faster than your timer
events, you will effectively delay the detail query until the
keyboard/mouse input has ceased, only fetching detail data
that will actually be displayed.
The only drawback : you always add a delay of 100  msecs
to the execution of the detail query, but your users won't
notice.

I am interested in any feedback/improvements/better ideas
etc...

Some code snippets :

Procedure TForm1.FormCreate(Sender: Tobject);
begin
  UpdateTimer.Enabled := False;   { reset the timer }
  .........
end;

Procedure TForm1.MasterDataChange(Sender TObject; Field : TField);
begin
{ you could check here for Field = nil (move to another row)
  or Field = part of the where clause used for the detail query }

{ if a timer event was  pending, cancel it }
   UpdateTimer.Enabled := False;

{ (re)start the timer that will fire the query }
   UpdateTimer.Interval := 100;
   UpdateTimer.Enabled := True;
end;

Procedure TForm1.UpdateTimerTimer(Sender : Tobject);
begin
{ cancel the timer }
  UpdateTimer.Enabled := False;

  DetailQuery.Close;
{ set the values used in the where condition }
  DetailQuery.Params[0].AsString := MasterQueryDetailkey.value;
{ set other values as needed }
   ....
{ fire the query }
  DetailQuery.Open;  
end;

Danny Heijl.
---------



Wed, 20 May 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. howto CloneCursor in master-detail ClientDataSet?

2. Master - Detail - Detail queries & DBGrids

3. Master->Detail->Detail Query Too Slow

4. which is faster using ttable or tquery in master detail form in SQL Server

5. Yet Another Master/Detail Sorting Query

6. Master Detail using Queries

7. Retreiving the number of detail records when querying the master

8. How to speed-up Master->Detail Queries ?

9. Master/detail performance-question (network/paradox/query)

10. Query on the subset in a master-detail table relationship

11. Master-Detail : Sorting Detail?

12. Setting report variables in the detail of a ReportSmith master-detail report

 

 
Powered by phpBB® Forum Software