>>> Is it possible to not return an instance of a class from its
>>> constructor?
>>>
>>> For example, say my constructor for SomeClass is:
>>>
>>> Sub Constructor(rs As RecordSet)
>>> dim d As Date
>>> dim fld As DatabaseField
>>>
>>> fld = rs.Field("EntryDate")
>>> if fld = nil Then Return
>>>
>>> // assign values to class properties
>>>
>>> End Sub
>>>
>>> Instead of returning a useless instance of SomeClass with none of
>>> its
>>> properties filled to the method that called the constructor, it
>>> would
>>> be nice if it were possible to return a nil object. Is it
>>> possible to
>>> do that?
>>
>> You can do this the cocoa way:
>>
>> dim c as class1
>> c = new class1
>> c = c.Init
>> // .Init may return nil
>>
>> In Cocoa, you can do this on one line, but it's still possible in RB,
>> just not as stylish. Cocoa does it like this:
>>
>> MyNSClass* Result = [[bla alloc] init];
>
>
> Here, alloc is a class method, and init is an object method.
>
>
> Using a shared method in REALbasic does the same thing, also in one
> line.
>
> dim c as Class1 = Class1.NewObject
OK. What about if the user wants to override the init method?
Like Class2 which subclasses from Class1?
dim c as class1
c = class2.NewObject.Init
that would make it possible, right? Oh, is that only if Class2
overrides Class1's NewObject function?
You just can't do this in RB.
c = (new class2).Init
Shame. It actually used to be possible sometime around RB 3 or 4 :)
--
http://elfdata.com/plugin/
"String processing, done right"
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>