Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Assigning value to property of object indirectly
Message
From
21/11/2015 16:31:37
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
21/11/2015 10:00:38
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01627690
Message ID:
01627736
Views:
50
>>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.
Previous
Reply
Map
View

Click here to load this message in the networking platform