看看代码例子
begin
TmpAErrorDs := AErrorDs;
TmpDataSet := DataSet;
CompareDs := TClientDataSetHack.Create(nil);
try
CompareDs.CloneCursor(TmpDataSet, False);
while not TmpDataSet.Eofdo
begin
case TmpDataSet.UpdateStatus of
usUnmodified : begin
//更新右子树
if Tree^.PRight <> nil then
do
Apply(DataSet, AErrorDs, Tree^.PRight);
//更新左子树
if Tree^.PLeft <> nil then
begin
TmpAErrorDs.Append;
do
Apply(TClientDataSetHack(TDataSetField(TmpDataSet.FieldByName(Tree^.PLeft^.FField)).NestedDataSet),
TClientDataSetHack(TDataSetField(TmpAErrorDs.FieldByName(Tree^.PLeft^.FField)).NestedDataSet),
Tree^.PLeft);
end;
end;
//记录被修改时, 明细记录本身是不保存在记录中的
usModified :do
Update;
//插入数据
usInserted : begin
do
Insert;
//更新右子树
if Tree^.PRight <> nil then
do
Apply(DataSet, AErrorDs, Tree^.PRight);
//更新左子树
if Tree^.PLeft <> nil then
begin
TmpAErrorDs.Append;
do
Apply(TClientDataSetHack(TDataSetField(TmpDataSet.FieldByName(Tree^.PLeft^.FField)).NestedDataSet),
TClientDataSetHack(TDataSetField(TmpAErrorDs.FieldByName(Tree^.PLeft^.FField)).NestedDataSet),
Tree^.PLeft);
end;
end;
usDeleted : begin
//更新右子树
if Tree^.PRight <> nil then
do
Apply(DataSet, AErrorDs, Tree^.PRight);
//更新左子树
if Tree^.PLeft <> nil then
begin
TmpAErrorDs.Append;
do
Apply(TClientDataSetHack(TDataSetField(TmpDataSet.FieldByName(Tree^.PLeft^.FField)).NestedDataSet),
TClientDataSetHack(TDataSetField(TmpAErrorDs.FieldByName(Tree^.PLeft^.FField)).NestedDataSet),
Tree^.PLeft);
end;
do
Delete;
end;
end;
TmpDataSet.Next;
end;
finally
CompareDs.Free;
end;
end;