Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

How to compare variants ?

已查看 1,425 次
跳至第一个未读帖子

Rik Netten

未读,
1998年1月17日 03:00:001998/1/17
收件人

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

未读,
1998年1月18日 03:00:001998/1/18
收件人

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

未读,
1998年1月18日 03:00:001998/1/18
收件人

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 个新帖子