Question
MARK PONGONIS · Dec 15, 2020

Using a variable to reference an object property

Anyone know if it's possible using cache objectscript (or something else maybe) to reference an object property using a variable? For example:

s obj={}

s obj.prop1="hello"

s var="prop1"

w obj.var    <== which would result in a reference to obj.prop1 and write out "hello"

Product version: Caché 2017.1
0
0 224
Discussion (7)1
Log in or sign up to continue

The following will work for you:

w obj.%Get(var)

No, no - *please* don't encourage the the use of eXecute ... that can make maintenance so very difficult :(  Most ObjectScript coding standards I have seen strictly forbid the use of this :) 

I'm not encouraging. I wouldn't use execute here but i would also encourage developers to know what execute is and why not to use it in most circumstances.