Information générale
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
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
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement