realbasic-nug
[Top] [All Lists]

Re: Operator_Compare with variant objects?

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Operator_Compare with variant objects?
From: Norman Palardy <npalardy@great-white-software.com>
Date: Sat, 30 May 2009 12:19:40 -0600
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <AEF09038-DB63-4857-BBE1-AE5D13AA6FF3@xochi.com>
References: <AEF09038-DB63-4857-BBE1-AE5D13AA6FF3@xochi.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com

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>


<Prev in Thread] Current Thread [Next in Thread>