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