Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to add property to an empty object?
Message
 
 
À
29/04/2021 01:10:28
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrats & ententes
Divers
Thread ID:
01680052
Message ID:
01680059
Vues:
28
>>Hi,
>>
>>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", "" )
>
Lutz,

Thank you for the explanation. The above code was simple to suppress and error if some other even fails. It should be rarely used and, if used, will minimize the run-time errors.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform