On 12-May-07, at 6:33 PM, Kiam wrote:

> ----- Original Message -----
> From: "Norman Palardy" <[EMAIL PROTECTED]>
> To: "REALbasic NUG" <[email protected]>
> Sent: Saturday, May 05, 2007 11:49 PM
> Subject: Re: overriding operator_convert not working?
>
>>
>> On 5-May-07, at 2:21 PM, kev wrote:
>>
>>> So I guess there's no way around this that will also maintain
>>> polymorphism?
>>
>> Use a constructor that takes a string ?
>>
>
> I think there is a little confusion around Operator_Convert().
> It should be used to convert from any datatype to a class instance.  
> So if I
> declare a Operator_Convert(input As String) in a class called  
> TestConvert,
> then I can write
>
> Dim value As New TestConvert
> value = "test"
>
> There is no need to control the class of the object, as long as the  
> class
> provides a right Operator_Convert().

Operator_Convert acts like a constructor.

If you have a class, like the original poster did, with a subclass  
and both have operator_convert implemented you get what appears to be  
odd behavior when you do something like

        dim v as SuperClassType

        v = new SubClassType

        v = "test" // if you check after doing this V is an instance of  
SuperClassType NOT SubClassType

in this case the operator_convert called is the on in the DEFINED  
type of v (the one in  the super class) because operator_convert does  
behave as a constructor and just a "conversion" from string to the  
type of v.

It's more like doing

        v = new SuperClassType

        v.TakeAStringAndAssignItToV("test")

and this TakeAStringAndAssignItToV is your custom method to rip a  
string into the various members of an instance of SuperClassType

Basically don't use operator_convert where you really want a  
constructor that takes a string because you can end up with  
unexpected behavior like this

If the original poster had written

        dim v as SuperClassType

        v = new SubClassType("test")

v would have been of the SubClassType as expected
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to