ClientDataset Delta Processing

I am having a problem with some code that the TClientDataSet Delta should handle, which I welded before the next test case.

I have two ClientDataSets, cdsData and cdsDelta, both with DataSource, DBGrid and DBNavigator, and TTreeView for displaying Delta Old- and NewValues.

In cdsDatas AfterPost, I call the DisplayDelta procedure below.

When I run the application, I change and save the value of one field in csdData, say, "PrevValue" to "UpdateValue". My problem is that both the OldValue and NewValue Nodes are displayed in the Treeview "UpdatedValue" window and there is no "PrevValue" sign. So how can I get OldValue right?

procedure TDeltaTestForm.DisplayDelta;
var
  Delta : OleVariant;
begin
  Delta := cdsData.Delta;
  if not VarIsClear(Delta) then begin
    cdsDelta.Data := Delta;
  end;
  if cdsData.Modified then
    Caption := 'modified'
  else
    Caption := '';
  Caption := Caption + '/' + IntToStr(cdsData.ChangeCount);
  BuildDeltaTree;
end;

procedure TDeltaTestForm.BuildDeltaTree;
var
  NewNode,
  ChildNode : TTreeNode;
  i,
  ID : Integer;
  Field : TField;
  Value : String;

  function ChildValue(ALabel : String; FieldValue : Variant) : String;
  begin
    Result := ALabel;
    if VarIsClear(FieldValue) then
      Result := Result + '(empty)'
    else
      if VarIsNull(FieldValue) then
        Result := Result + '(null)'
      else
        Result := Result + VarToStr(FieldValue);
  end;
begin
  { Find the current row in the delta dataset }

  ID := cdsData.FieldByName('ID').AsInteger;
  if not cdsDelta.Locate('ID', ID, []) then
    raise Exception.CreateFmt('ID: %d not found in Delta', [ID]);

  TreeView1.Items.BeginUpdate;
  try
    Treeview1.Items.Clear;
    for i:= 0 to cdsDelta.FieldCount - 1 do begin
      Field := cdsDelta.Fields[i];
      NewNode := TreeView1.Items.AddChild(Nil, Field.FieldName);
      ChildNode := TreeView1.Items.AddChild(NewNode, ChildValue('Old: ', Field.OldValue));
      ChildNode := TreeView1.Items.AddChild(NewNode, ChildValue('New: ', Field.NewValue));
      ChildNode := TreeView1.Items.AddChild(NewNode, ChildValue('Cur: ', Field.CurValue));
    end;
    TreeView1.FullExpand;
  finally
    TreeView1.Items.EndUpdate;
  end;
end;
+4
1

. :

for i:= 0 to cdsDelta.FieldCount - 1 do begin
  Field := cdsDelta.Fields[i];

for i:= 0 to cdsData.FieldCount - 1 do begin
  Field := cdsData.Fields[i];

, OldValue NewValue, . , .

, - , Delta CDS , - (Old New), Delta, , , . "ClientDataSets" ( "StatusFilter Versus Delta" 6), :

"... CDS CDS Delta, CDS ."

, , , . , cdsDelta Field.OldValue Field.NewValue.

+4

Source: https://habr.com/ru/post/1652613/


All Articles