On 30-May-09, at 11:34 AM, Michael Diehr wrote:
If a variant holds an object, then Variant.StringValue will
automatically call Operator_Convert for the object (assuming it has
"Operator_Convert() as string" defined).
However, this does not seem to hold true for Operator_Compare when
comparing variants.
Am I doing something wrong or is this just how it goes?
Code:
dim v1 as variant = new cMyClass
dim v2 as variant = new cMyClass
// this calls cMyClass.Operator_Convert
if v1.stringValue = v2.StringValue then ...
// this does NOT call cMyClass.Operator_Copmare
if v1 <> v2 then ...
Class cMyClass
function Operator_Convert() as string
return "foobar"
end function
function Operator_Compare(rhs as cMyClass) as integer
return -1
end function
This makes sense
if v1.stringValue = v2.StringValue then ...
certainly clues the compiler in to which kind of conversion you intend
but
if v1 <> v2 then ...
gives no clue - you might want
if v1.StringValue <> v2.StringValue then ...
or if v1.IntegerValue <> v2.IntegerValue then ...
or if v1.ObjectValue <> v2.ObjectValue then ...
or any others
How would the compiler guess which you intended ?
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|