function TForm5.IsFieldChanged(aDataSet: TkbmMWCustomClientQuery; aFieldName: string): Boolean; var i: TkbmNativeInt; pRec, pOrigRec, pOldRec: PkbmRecord; aOldV, aNewV: Variant; begin if ADataSet.FindField(aFieldName)=nil then raise EMemTableError.Create('當前數據集無此字段.'); Result:=False; pRec := pkbmRecord(aDataSet.ActiveBuffer); if pRec = nil then Exit; if pRec^.UpdateStatus = usModified then with aDataSet do begin
pOrigRec:=pRec; while pOrigRec^.PrevRecordVersion <> nil do begin pOrigRec := pOrigRec^.PrevRecordVersion; end;
pOldRec := OverrideActiveRecordBuffer; try OverrideActiveRecordBuffer := pRec; // 指向修改後的數據 aNewV := FieldByName(aFieldName).Value; OverrideActiveRecordBuffer := pOrigRec; // 指向修改前的數據 aOldV := FieldByName(aFieldName).Value; if aNewV <> aOldV then begin Result:=True; end; finally OverrideActiveRecordBuffer := pOldRec; end; end; end;