Nil denotes the absence of an object in a variable which is typed to hold an object. Hence Nil is not typed and it is not an Object (the Xojo base class) or a subclass thereof.
Again since Norman already stated that you are trying to apply Operator_Convert to Nil that is the real problem.
Dim p As Picture = Nil.Operator_Convert() // not possible
What you need is an instance of the class where Operator_Convert is defined:
Dim p As Picture = aNewPictureSubclassInstance.Operator_Convert() // this will work and return Nil or the
// picture stored in mPicture
Of course one leaves away Operator_Convert:
Dim p As Picture = aNewPictureSubclassInstance // this will work
[quote=208795:@Michael Diehr]function GetANilPicture as NewPictureSubclass
return new NewPictureSubclass(Nil)
end function
I suppose one could do it that way, but that gets really messy - you would then have to remember while debugging whether NIL means NIL or whether “NIL” is flagged by sending a non-nil object that would automatically operator_convert() to NIL on the fly.[/quote]
I don’t understand what would be messy here. That is the proper way to do it. That’s what Operator_Convert exists for. It is clean and works well.
To be honest, I don’t understand the second part of your sentence [i]“NIL” is flagged by sending a non-nil object that would automatically operator_convert() to NIL). What do you mean by that?
Operator_Convert (the “To” one, the function) returns the picture it wraps (in the above case the private mPicture property). If mPicture is Nil it will return Nil, if mPicture contains a picture it will return that. You define it. There is no built-in, automatic conversion.
[code]Dim pNew1 As NewPictureSubclass = New NewPictureSubclass(New Picture(1, 1, 32))
Dim pNew2 As NewPictureSubclass = New NewPictureSubclass(Nil)
// the two lines above could be written as:
Dim pNew1 As NewPictureSubclass = New Picture(1, 1, 32) // same as first line
Dim pNew2 As NewPictureSubclass = Nil // same as second line, but will NOT work as Operator_Convert
// can not be applied to Nil
Dim pic1 As Picture = pNew1 // will work, pic1 will contain the picture
Dim pic2 As Picture = pNew2 // will work, pic2 will be Nil[/code]