Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Difference between thisForm.addObject() and newObject()
Message
De
08/02/2005 16:23:21
 
 
À
05/02/2005 11:20:32
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Network:
Windows 2000 Pro
Database:
Visual FoxPro
Divers
Thread ID:
00984088
Message ID:
00984916
Vues:
25
Randy, thanks for the anwser. I get the picture. I posted my question because I have inherited two clases (for which I don't have the time to learn and refactor) that are more tightly coupled than I would like to.
I have to release them from memory in a certain order, and if I add them with thisForm.addObject I cannot control the order in which they are destroyed. So I will keep adding the property first and then assigning the property to a new object.

Thanks,
Javier.

>The biggest difference is that the first method creates a member of the form using true VFP containership model, whereas the second merely uses a property of the form to "hold" an object reference to a non-contained object.
>
>Without containership the non-visual object will have no Parent property, and thus has no way to reference the form or its members. IOW, THISFORM and THIS.Parent will both be unavailable. Whether this is OK, depends on how the object is called. Where you can get into garbage collection problems is trying to "solve" that limitation by adding a property to the object that keeps a reference to the form. This is dangerous territory, and you should strongly consider the containership (AddObject) approach if you find yourself heading down that path.
>
>To your final question, ADD OBJECT in the constructor is much like AddObject() -- both employ containership. However, you cannot use the alternative in the constructor, but rather would need to call NEWOBJECT() elsewhere, such as the INIT or LOAD methods.
>
>-- Randy
>
>
>>Hi all,
>>
>>I want to "attach" a non visual object to a form (to be used along the code in the form).
>>I would like to know what are the differences between:
>>
>>thisForm.addObject('myObjectName', 'myClass')
>>
>>and
>>
>>thisForm.myObjectName = newObject('myClass') && of course myObjectName is a defined property
>>
>>Are there any advantages on using one or the other? Which one is better in terms of memory release (garbache collection)? Do I have to have special precautions with one or the other?
>>I think that the same applies to ADD OBJECT in DEFINE CLASS (versus myClass.myObject = newObject()), does it?
>>
>>Thanks in advance,
>>Javier.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform