Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to add property to an empty object?
Message
From
29/04/2021 04:18:59
 
 
To
29/04/2021 01:10:28
Lutz Scheffler (Online)
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
General information
Forum:
Visual FoxPro
Category:
Contracts, agreements and general business
Miscellaneous
Thread ID:
01680052
Message ID:
01680054
Views:
48
@Dmitry:
technical stuff already explained in detail, let me add my mental rules of thumb(s):
If adding any object to objects not based on EMPTY, default to .AddObject(), as cleanup is automatic. your
>>	LOCAL oTableInfo
>>	oTableInfo = CREATEOBJECT("empty")
>>	ADDPROPERTY( oTableInfo, "config_xml", "" )
>>    toObject.AddProperty("oTableInfo", oTableInfo)
runs against my rule. No worry, no fines set - this time ;-))

If UC needs objects added either into EMPTY.property or there is sufficient reason not to follow rule above, either have a recursive pre-destroy function available running down or standardize on specific property housing array of object property names for specific project and run pre-destroy on that. If you go 2. way, create function to automatically insert property name into that array when adding property AND always be careful not to assign objects later into existing properties. If it happens only few times, Hungarian name prefix on property names can be enough for easy to track cleanup, but even then a addObj() function is nice to force Hungarian naming if not going for property name array.

>>I want to create an empty object as a property of another object. Then add a couple of properties to the empty object.
>>Here is what I know how to do:
>>
>>toObject.AddProperty("oTableInfo", "Empty")
>>
>>
>>Then, I need to add a property 'config_xml' to the oTableInfo and set it to empty string (''). I tried the following:
>>
>>AddProperty( toObject.oTableInfo, "config_xml", "")
>>
>>
>>But the above gives a run-time error. What am I missing?
>>
>>TIA
>>
>>UPDATE: This works:
>>
>>	LOCAL oTableInfo
>>	oTableInfo = CREATEOBJECT("empty")
>>	ADDPROPERTY( oTableInfo, "config_xml", "" )
>>    toObject.AddProperty("oTableInfo", oTableInfo)
>>
>>
>>Let me know if the above works but wrong.
>
>TL;DR:
>Your example should work as long as toObject is not empty object.
>This might be more secure:
>
>LOCAL oTableInfo
>oTableInfo = CREATEOBJECT("empty")
>ADDPROPERTY( oTableInfo, "config_xml", "" )
>ADDPROPERTY( toObject, "oTableInfo", oTableInfo)
>
>
>Long:
>This is the syntax for empty object:
>
>LOCAL oTableInfo
>oTableInfo = CREATEOBJECT("empty")
>ADDPROPERTY( oTableInfo, "config_xml", "" )
>
>
>This is because the empty object is empty - it exposes no methods or events - so there is no .AddProperty() method and you must use the AddProperty() function.
>
>Any other object works both ways
>
>LOCAL oTableInfo
>oTableInfo = CREATEOBJECT("custom")
>ADDPROPERTY( oTableInfo, "config_xml", "" )
>oTableInfo.AddProperty("SomeProp", vSomeValue)
>
>
>Conclusio, long code short:
>
>ADDPROPERTY( toObject, "oTableInfo",  CREATEOBJECT("empty") )
>ADDPROPERTY( toObject.oTableInfo, "config_xml", "" )
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform