GuidoG
GuidoG

Reputation: 12059

Delphi clientdataset does not navigate when disablecontrols is called

I have a datamodule with 3 clientdatasets, all coupled through datasetproviders to a adoquery. PacketRecords is set to -1 on each clientdataset. cds2 has a masterdetail with cds1 cds3 has a masterdetail with cds2

So on my form, when I move to another record in the cds1 than cds2 and cds3 follow as expected.

Now I need to loop through all the records of cds3 to make a sum of some fields. No problem using the code below, works like a charm. (max 5 records present at all times)

cds2.First;
while not cds2.Eof do
begin
  cds3.First;
  while not cds3.Eof do
  begin
    TotalExcl := TotalExcl + cds3TotalExcl.AsCurrency;
    TotalIncl := TotalIncl + cds3TotalIncl.AsCurrency;

    cds3.Next;
  end;

  cds2.Next;
end;

But offcourse I did not want the dbgrids to move after each call to first and next, so I called disablecontrols on cds2 and cds3

The problem is that not only do the dbgrids stopped moving, but also the clientdatasets do not move anymore ! Calling first and next on cds2 or cds3 does absolutly nothing anymore until I remove the disablecontrols.

Is this normal behaviour when using clientdatasets in masterdetail relationships ? If so, is there a workaround to bypass this "feature" ?

I use disablecontrols all the time, never had a problem yet, but this is the first time I use it on 3 clientdatasets that have masterdetails setup.

Upvotes: 0

Views: 1341

Answers (1)

GuidoG
GuidoG

Reputation: 12059

A solution has been given to me by Sertac Akyuz.

It seems that calling DisableControls on a clientdataset also disables the master/detail relationship.

So if you want to loop through all the records of a clientdataset that is in a master/detail relationship you cannot call DisableControls. In stead you can set the property BlockReadSize to a positive value, which has the same effect as disablecontrols but does not disables the master/detail relation ship

The working code I have now is :

cds2.BlockReadSize := 10;
cds3.BlockReadSize := 10;

try
  cds2.First;
  while not cds2.Eof do
  begin
    cds3.First;
    while not cds3.Eof do
    begin
      TotalExcl := TotalExcl + cds3TotalExcl.AsCurrency;
      TotalIncl := TotalIncl + cds3TotalIncl.AsCurrency;

      cds3.Next;
    end;

    cds2.Next;
  end;
finally
  cds2.BlockReadSize := 0;
  cds3.BlockReadSize := 0;
end;

Upvotes: 2

Related Questions