Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using ADDOBJECT vs CREATEOBJECT/NEWOBJECT?
Message
From
22/09/2002 20:30:57
 
 
To
21/09/2002 09:03:49
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00702890
Message ID:
00703222
Views:
15
Thought it had something to do with the "is a" vs "has a" relationship and how things are better cleaned up using ADDOBJECT to a container.

>>I am looking at some older code I wrote where I have attached several objects to a custom class such as follows:
>>
>>
>>this.oEnvironment = NEWOBJECT('env','utils')
>>etc...
>>
>>
>>I have seen others use ADDOBJECT to do the same. What are the pros and cons of each? I would guess that garbage collection is better with ADDOBJECT.
>>
>>Some clarification on this would be very helpful...
>
>Tom,
>AFAIK has nothing to do with garbage collection. NewObject() is newer < g > in language (from VFP6).
>When you use AddObject() there is no parameter to specify from which classlib that class would come and you needed extra lines like 'set classlib to ...'
>With NewObject() you have parameters to specify where the classlib is.
>
>Object.AddObject(cName, cClass [, cOLEClass] [, aInit1, aInit2 ...])
>
>Object.NEWOBJECT(cObjectName, cClassName [, cModule [, cInApplication [, eParameter1, eParameter2, ...]]])
>
>ie: Suppose you want to add object as MyClass from MyClassLib.vcx
>
>
>if !'MYCLASSLIB.VCX'$ set('classlib')
>  set classlib to myClassLib.vcx additive
>endif
>this.AddObject('ObjectNameHere','MyClass')
>* or
>if !'\MYFIRSTCLASSLIB\MYCLASSLIB.VCX'$ set('classlib')
>  set classlib to myClassLib.vcx additive alias firstcl
>endif
>*...
>if !'\MYSECONDCLASSLIB\MYCLASSLIB.VCX'$ set('classlib')
>  set classlib to myClassLib.vcx additive alias secondcl
>endif
>this.AddObject('ObjectNameHere','secondcl.MyClass')
>
>
>vs:
>this.NewObject('ObjectNameHere','MyClass','myClassLib.Vcx')
>
>this.NewObject('ObjectNameHere','MyClass','mySecondClassLib\myClassLib.Vcx')
>
>
NewObject has even another parameter making it easy to get classlib from an existing app. Same goes with CreateObject() vs NewObject() functions.
>Cetin
Previous
Reply
Map
View

Click here to load this message in the networking platform