TDeltaDataSet是用来更方便的分析数据集中的Delta(数据集的修改日志)。通常会使用TDeltaDataSet来遍历修改日志,以便获取需要做修改记录的数据。TDeltaDataSet类在Business.Data中。参考代码如下:
…
//此处是判断被分析的数据必须处于激活并修改状态
if DataSetBZSJJ1.Active and DataSetBZSJJ1.UpdatesPending then
Exit;
lDeltaDataSet:= TDeltaDataSet.Create(DataSetBZSJJ1);
try
while not uLogDs.Eof do
begin
case uLogDs.UpdateKind of
//修改
TUpdateKind.ukModify:
begin
Memo1.Lines.Add('Modify');
//记录修改的字段
for I := 0 to uLogDs.Fields.Count - 1 do
begin
lField := uLogDs.Fields[I];
if uLogDs.FieldModified(lField) then
Memo1.Lines.Add(Business.System.SysUtils.Format('FieldName:[%s]Old:[%s]
New:[%s]',[lField.FieldName,Business.System.Variants.VarToStr
(lField.OldValue),Business.System.Variants.VarToStr(lField.NewValue)]));
end;
end;
//插入
TUpdateKind.ukInsert:
begin
Memo1.Lines.Add('Insert');
end;
//删除
TUpdateKind.ukDelete:
begin
Memo1.Lines.Add('Delete');
end
else
Assert(False, '');
end;
uLogDs.NextStatus
end;
finally
uLogDs.Free;
end; |