Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to compare variants ?

1,415 views
Skip to first unread message

Rik Netten

unread,
Jan 17, 1998, 3:00:00 AM1/17/98
to

Does anyone know how to compare to variables of type Variant ?
(the simple "v1 = v2" does not work).

Something like:
function AreVariantsEqual(v1, v2: variant): boolean;

Where v1 and v2 can be simple variants but also variant arrays.

Thank you for answering.

Peter Below

unread,
Jan 18, 1998, 3:00:00 AM1/18/98
to

In article <69qoag$g4...@forums.borland.com>, Rik Netten wrote:
> Does anyone know how to compare to variables of type Variant ?
> (the simple "v1 = v2" does not work).
>

It does work but it compares the variant values in a way that may involve
variant conversions. And of course it will fail with variant arrays. There
is no generic way to compare two variants of arbitrary type and content for
equality. You have to build code that handles the possible cases in a
sensible fashion, e.g.

- compare the variant types
- if equal
- do we have variant arrays
- if so, compare the number of elements
- if equal and not a array of variant, compare the values
- if equal and an array of variant, repeat whole process
for each array element
- if no variant array, compare the values

Peter Below (TeamB) 10011...@compuserve.com)


Steve Zimmelman

unread,
Jan 18, 1998, 3:00:00 AM1/18/98
to

A simple way to compare would be something like this:

Function VariantCompare(v1,v2:Variant) : Boolean;
Begin
Result := False ;
If (VarType(v1) = VarType(v2)) Then Begin
Result := (v1 = v2) ;
End;
End;

If the Variant Types are the same then compare them, otherwise assume that
they are different because they are different Types.

-Steve-
---------
Rik Netten <"nett...@wxs.nl"@wxs.nl> wrote in message
<69qoag$g4...@forums.borland.com>...


>Does anyone know how to compare to variables of type Variant ?
>(the simple "v1 = v2" does not work).
>

0 new messages