红鱼儿

公告

统计

  • 随笔 - 121
  • 文章 - 1
  • 评论 - 24
  • 引用 - 0
kbmMWClientQuery判断一个字段是否修改?
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;

 

posted on 2019-05-10 16:52 红鱼儿 阅读(...) 评论(...) 编辑 收藏