Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Assigning value to property of object indirectly
Message
De
21/11/2015 08:35:06
 
 
À
20/11/2015 17:27:44
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:
01627726
Vues:
58
>Hi all,
>
>This is probably a "Friday afternoon brain fart" type of thing but coding a utility class that has a function where I pass in:
>
>tcObjectName
>
>tcProperty
>
>tuValue
>
>That is, I want to have a generic function that assigns a value to a property of an object. I first loop through a collection to get an object reference to the named object to yield toSavedObject
>
>I know this works:
>
>
>
>STORE tuValue TO toSavedObject.&tcProperty
>
>
>
>Is there any other way to get the value into the property without using the ampersand?
>
>I tried indirection but that did not work e.g.
>
>
>
>STORE tuValue TO ( toSavedObject + "." + tcProperty )
>
>
>
>I know I can keep trying but figure I would ask and maybe there would be an answer when I get in Monday morning :-)
>

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.

Tamar
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform