function VariantBasicTypeName(varVar: Variant):String;
var
basicType : Integer;
begin
basicType := VarType(varVar) and VarTypeMask;
case basicType of
varEmpty : Result := 'Empty';
varNull : Result := 'Null';
varSmallInt : Result := 'SmallInt';
varInteger : Result := 'Integer';
varSingle : Result := 'Single';
varDouble : Result := 'Double';
varCurrency : Result := 'Currency';
varDate : Result := 'Date';
varOleStr : Result := 'OleStr';
varDispatch : Result := 'Dispatch';
varError : Result := 'Error';
varBoolean : Result := 'Boolean';
varVariant : Result := 'Variant';
varUnknown : Result := 'Unknown';
varByte : Result := 'Byte';
{$ifdef VER140}
varWord : Result := 'Word';
varLongWord : Result := 'LongWord';
varInt64 : Result := 'Int64';
{$endif}
varStrArg : Result := 'StrArg';
varString : Result := 'String';
varAny : Result := 'Any';
varTypeMask : Result := 'TypeMask';
Else Result := Format('Custom(%d)',[basicType]);
end;
end;
function VariantTypeName(varVar: Variant):String;
var
ExtType,i : Integer;
begin
ExtType := VarType(varVar);
Result:=VariantBasicTypeName(varVar);
if (ExtType And varArray)>0 Then
begin
Result:=Result+'[';
for i:=1 to VarArrayDimCount(varVar) do Result:=Result+Format('%d,',[VarArrayHighBound(varVar,i)-VarArrayLowBound(varVar,i)+1]);
Result[Length(Result)]:=']';
end;
if (ExtType And varByRef)>0 Then Result:='@'+Result;
end;
function VariantAsString(varVar:Variant):String;
Var
// L:TStringList;
basicType,i,j,Dim : Integer;
begin
basicType := VarType(varVar) and VarTypeMask;
if VarIsArray(varVar) then
begin
Dim:=VarArrayDimCount(varVar);
if Dim>2 Then
begin
Result:='Array '+VariantTypeName(varVar);
Exit;
end;
Result:='[';
if Dim=1
Then for i:=VarArrayLowBound(varVar,1) to VarArrayHighBound(varVar,1) do Result:=Result+VariantAsString(varVar[i])+','
Else for i:=VarArrayLowBound(varVar,1) to VarArrayHighBound(varVar,1) do
begin
Result:=Result+#13#10' [';
for j:=VarArrayLowBound(varVar,2) to VarArrayHighBound(varVar,2) do Result:=Result+VariantAsString(varVar[i,j])+',';
Result[Length(Result)]:=']';
Result:=Result+' ,';
end;
Result[Length(Result)]:=']';
end else
begin
if VarIsEmpty(varVar) Then Result:='(Empty)' Else
if VarIsNull(varVar) Then Result:='(Null)' Else Result:=VarToStr(varVar);
end;
end;
|