TkbmMWClientQuery有一个属性:IsDataModified,表示记录是否被修改过,实测的结果,当为一个字段赋值一个相同的值时,IsDataModified也会变为True。
q.Edit;
q.FieldByName('FName').AsString:='test';
q.Post;
象上面的代码,当q.FieldByName('FName').AsString已经等于test时,IsDataMoodified也会由False变为True,这不是我想要的。
试图修改源码,解决这个问题,无奈太复杂,搞不定,按Q友竹子的提示,修改他提取Delta的代码,改写了一个方法,测试通过:
function TDbCache.DataSetIsDataModified(
akbmMemTable: TkbmCustomMemTable): Boolean;
var
i: TkbmNativeInt;
j: TkbmNativeInt;
pRec, pOrigRec, pOldRec: PkbmRecord;
aRecords: TkbmList;
st: TUpdateStatus;
aOldV, aNewV: Variant;
begin
if akbmMemTable.State in [dsInsert, dsEdit] then
akbmMemTable.Post;
Result := False;
with akbmMemTable do
begin
aRecords := Common.Records;
for i := 0 to aRecords.Count - 1 do
begin
pRec := PkbmRecord(aRecords.Items[i]);
if pRec = nil then
begin
Continue;
end;
// Find oldest version.
pOrigRec := pRec;
while pOrigRec^.PrevRecordVersion <> nil do
begin
pOrigRec := pOrigRec^.PrevRecordVersion;
end;
// Check what status to react on.
if pRec^.UpdateStatus = usDeleted then
begin
// Dont resolve inserts that were deleted again.
if pOrigRec^.UpdateStatus = usInserted then
st := usUnmodified
else
st := usDeleted;
end
else if pOrigRec^.UpdateStatus = usInserted then
st := usInserted
else
st := pRec^.UpdateStatus;
pOldRec := OverrideActiveRecordBuffer;
try
if st = usModified then
begin
OverrideActiveRecordBuffer := pRec; // 指向修改后的数据
for j := 0 to FieldCount - 1 do
begin
OverrideActiveRecordBuffer := pRec; // 指向修改后的数据
aNewV := FieldByName(Fields[j].FieldName).Value;
OverrideActiveRecordBuffer := pOrigRec; // 指向修改前的数据
aOldV := FieldByName(Fields[j].FieldName).Value;
if aNewV <> aOldV then
begin
Result:=True;
Break;
end;
end;
end
else if st = usInserted then
begin
Result:=True;
end
else if st = usDeleted then
begin
Result:=True;
end
else if pRec.UpdateStatus = usUnmodified then
begin
end;
finally
OverrideActiveRecordBuffer := pOldRec;
end;
if Result then
Break;
end;
end;
end;
用这个方法,在q.Resolve前,可以判断是否修改了。
再一次感谢清幽傲竹!