Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
NewObject() vs AddObject()
Message
From
12/02/2008 22:34:39
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
12/02/2008 21:26:06
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
01292009
Message ID:
01292017
Views:
26
>>>I can't quite grok the help, and in actual practice I have only used AddObject (as well as CreateObject()). Is there any difference in behavior between the two functions - NewObject() and AddObject() - apart from the slightly different syntax (for instance, NewObject allows specifying a class library)?
>>>
>>>TIA,
>>>
>>>Hilmar.
>>
>>NewObject() is the equivalent of CreateObject() except that CreateObject() requires that you have either the PROCEDURE file or CLASSLIB set. Addobject simply creates a property to which you can assign the new object
>>SET PROCEDURE TO myProc
>>this.addproperty("newProp",CREATEOBJECT("myclass_in_myproc"))
>>
>>SET PROCEDURE TO
>>this.addproperty("secondprop",NEWOBJECT("myclass_in_myproc","myproc.prg"))
>
>Sorry, but aren't you confusing AddObject() with AddProperty()?

There is a substantial difference. Object added as a property is just a property which is an object pointer, but that object isn't a member (i.e. its .parent is null, it's not among oObject.objects). OTOH, oObject.addobject(...) and oObject.NewObject(.....) will create a member object. For the outside world this new object behaves the same (the syntax oObject.newlyaddedobject.property will be the same), but newlyaddedobject.parent=oObject, and newlyaddedobject is a member of oObject.objects collection.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform