Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Difference and When to use NEW/ADD/CREATEOBJECT()
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00894349
Message ID:
00894464
Views:
10
This message has been marked as a message which has helped to the initial question of the thread.
Bhavbhuti,

AddObject() puts the object into the containership hierarchy. This allows and is required for the object to be visible and to participate in the UI event loop in the case of a form.

assuming your form has a property LabelX:
thisform.LabelX = CreateObject( "label" )
You can not make this label visible, nor will it respond to mouse clicks. The label object itself does not have a valid object reference in the .Parent property. You are responsible to set thisform.LabelX = .null. at some point during the destruct sequence to properly clean up the object. The form.Objects[] collection does not contain a reference to the label. The same comments apply if you use NewObject() instead of CreateObject().
thisform.AddObject( "LabelY", "label" )
thisform.Visible = .t.
The object LabelY can receive UI events, it's .Parent property references the form. You can access the label via the form.Objects[] collection. When the form destructs it will automatically take care of the destruction of the object.

>Being a relative newbie, I have used these 3 in different situations but without much insight, because they worked I kept them.
>
>What are the differences (except for parameters) and when are they to be used (in proper context)
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform