TClientDataSetの デルタを処理するはずのコードで問題が発生しましたが、これは次のテストケースに沸かせました。ClientDataSetのデルタの処理
私は、DataSource、DBGrid 、DBNavigator、DeltaのOld-とNewValuesを表示するためのTTreeViewの2つのClientDataSet cdsDataとcdsDeltaを持っています。
cdsDatas AfterPostでは、以下のDisplayDeltaプロシージャを呼び出します。
私はアプリを実行すると、csdDataの1フィールドの値を変更して、 から 'PrevValue'を 'UpdatedValue'に変更して保存します。私の問題は、ツリービューの OldValueとNewValueノードの両方が 'UpdatedValue'を表示し、 'PrevValue'の記号がないことです。だから、どうすればOldValueを正しく取得できますか?
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;
Hmm。あなたのツリービューの子ノードのコードは、RecErr.Pas(提供されているエラー調整フォーム)のコードと非常によく似ています。私はボランダール元Mark EdingtonのNG投稿を曖昧に覚えています。後で... – MartynA
デルタレコードを処理する方法を知るためにprovider.pasとTPacketDataSet.InitAltRecBuffersを参照してください – vavan