Reputation: 274
I having a bit of an issue tracking the changes to just fkData fields in a ClientDataSet.
There are fkInternalCalc fields that I populate and change quite a bit while using the program (I'll use an fkInternalCalc field to drive calculations to other fkInternalCalc fields).
I can call CDS.ChangeCount and get a result of 0 (because none of the fkData fields have actually changed).
But when I call CDS.StatusFilter:=[usModified] I see many records - because while ChangeCount ignores fkInternalCalc, StatusFilter doesn't - it shows changes to everything.
Am I missing some mechanism whereby I can filter by (usmodified and fkData)?
(I can't use simple fkCalculated for a variety of performance reasons)
Using Delphi Tokyo Enterprise.
TIA Cheers, EdB
Upvotes: 1
Views: 202
Reputation: 30715
I think the code below will do what you want, if I understand you correctly. It's just a test-bed, requires 2 CDSs each with a datasource and grid.
As you can see, the ClientDataSet1Value field gets updated every time a change is posted to the first CDS, but the second CDS only shows rows where an fkData field has been changed;
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
begin
{
ClientDataSet1ID: TIntegerField; // fkData
ClientDataSet1Name: TStringField; // fkData
ClientDataSet1SaveCount: TIntegerField; // fkInternalCalc
}
ClientDataSet1.CreateDataSet;
for i := 1 to 3 do
ClientDataSet1.InsertRecord([i, 'name of ' + IntToStr(i)]);
end;
procedure TForm1.ClientDataSet1BeforePost(DataSet: TDataSet);
begin
if ClientDataSet1SaveCount.IsNull then
ClientDataSet1SaveCount.AsInteger := 1
else
ClientDataSet1SaveCount.AsInteger := 1 + ClientDataSet1SaveCount.AsInteger;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ClientDataSet2.Data := ClientDataSet1.Data;
ClientDataSet2.StatusFilter := [usModified];
end;
After Button2Click
, the grid for the second CDS will be displaying only the rows whose fKData field(s) have been modified, or a single blank row if none of the rows have modified fkData field data.
Upvotes: 1