Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using ADDOBJECT vs CREATEOBJECT/NEWOBJECT?
Message
From
21/09/2002 09:03:49
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
20/09/2002 15:03:58
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00702890
Message ID:
00703044
Views:
19
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform