首页  编辑  

判断两个变体值是否相等

Tags: /超级猛料/Friends.网友专栏/zswang/函数大全/   Date Created:

(*//

标题:判断两个变体值是否相等

说明:可以用来检查不同数据集记录值是否相同

设计:Zswang

日期:2002-01-26

支持:wjhu111@21cn.com

//*)

///////Begin Source

function VarIsEqual(mVar1, mVar2: Variant): Boolean; { 返回两个变体值是否相等 }

var

 vType1, vType2: TVarType;

 I: Integer;

 vVarLow1, vVarLow2: Integer;

 vVarHigh1, vVarHigh2: Integer;

begin

 Result := False;

 vType1 := VarType(mVar1);

 vType2 := VarType(mVar2);

 if vType1 <> vType2 then Exit;

 if vType1 and varArray <> 0 then begin

   vVarLow1 := VarArrayLowBound(mVar1, VarArrayDimCount(mVar1));

   vVarLow2 := VarArrayLowBound(mVar2, VarArrayDimCount(mVar2));

   if vVarLow1 <> vVarLow2 then Exit;

   vVarHigh1 := VarArrayHighBound(mVar1, VarArrayDimCount(mVar1));

   vVarHigh2 := VarArrayHighBound(mVar2, VarArrayDimCount(mVar2));

   if vVarHigh1 <> vVarHigh2 then Exit;

   for I := vVarLow1 to vVarHigh1 do

     if not VarIsEqual(mVar1[I], mVar2[I]) then Exit;

   Result := True;

 end else Result := VarCompareValue(mVar1, mVar2) = vrEqual;

end; { VarIsEqual }

///////EndSource

///////Begin Demo

procedure TForm1.Button1Click(Sender: TObject);

var

 vFields1: string;

 vFields2: string;

begin

 vFields1 :=

   StringReplace(Trim(Table1.FieldList.Text), #13#10, ';', [rfReplaceAll]);

 vFields2 :=

   StringReplace(Trim(Table2.FieldList.Text), #13#10, ';', [rfReplaceAll]);

 CheckBox1.Checked := VarIsEqual(Table1[vFields1], Table2[vFields1]);

end;

///////End Demo