Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Assigning value to property of object indirectly
Message
De
21/11/2015 16:31:37
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
21/11/2015 10:00:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01627690
Message ID:
01627736
Vues:
49
>>Use EVAL() to turn the name of an object into an object reference:
>>
>>
oSavedObject = EVAL(m.tcObjectName)
>>
>>You probably want to wrap that in TRY-CATCH in case the object doesn't exist.
>>You can then use EVAL again to reference the property:
>>
>>
>>STORE m.tuValue TO EVAL("m.oSavedObject." + m.tcProperty)
>>
>>
>>Of course, it's easier to just pass the object in the first place.
>
>Sorry, no! Treat your CPU well!
>store m.toValue to (m.tcObjectName + "." + m.tcProperty) is enough, no need for 2 eval() calls - perhaps try catch, but nothing else
>If oSavedObject = EVAL(m.tcObjectName) works, as the name is in scope and not somewhere in a hierarchy, the store will work as well, provided the property exists
> ;-)

Actually
oSavedObject = EVAL(m.tcObjectName)
addproperty(oSavedObject, tcProperty, tuValue)
...should always work, except in some cases when property is protected or hidden - and checking for that is a good enough reason to make this a method or procedure. Otherwise, addproperty() would do the same without any need to call a method/procedure. Handling the case when we don't want to create a property if it didn't already exist is another reason.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform