On Apr 16, 2007, at 6:51 PM, Theodore H. Smith wrote:

>> 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

Charles Yeomans
_______________________________________________
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