eval

cangelo
Say I have an object with a property like:

myObject:myValue = "some string"


Also say I have 2 string variables:

tempObj = "myObject"
tempProp = "myValue"


I would like to do two things:

- get the object's property value via these temp strings

msg <#tempObj#:#(tempObj):tempProp#>
will display tempObj:tempProp which is great, but I want to evaluate this one more time to print the value "some string"

- set the object's property value via these temp strings

Alex
You can use the $objectproperty$ function for this. Although officially obsolete since the #object:property# syntax was introduced, it's still useful for things like this.

So you can use this:


msg <$objectproperty(#tempObj#; #tempProp#)$>


And to set the value:


property <#tempObj#; #tempProp# = some other string>

cangelo
Perfect. I thought about trying this lastnight but was turned off to it because the help file said it was obsolete.

Of course I hate to depend on obsolete functions in my code/libraries, so what is the future of this functionality?

Alex
It will continue to be available because it's the only way of doing things like this (although it is obsolete for most purposes i.e. when you're not using a variable in the parameters).

cangelo
Alex wrote:It will continue to be available because it's the only way of doing things like this (although it is obsolete for most purposes i.e. when you're not using a variable in the parameters).


It showed useful in another situation that I was unable to figure another way to handle...accessing an array property of an object.


for <myNum; 1; 5; 1> {
set string <cTemp;$objectproperty(#cRealObj#; testArray[%myNum%])$>
}

Elexxorine
for <myNum; 1; 5; 1> {
set string <cTemp;$objectproperty(#cRealObj#; testArray[myNum])$>
}
No '%'s are needed within index brackets, as only numbers can go there anyway. Just though I'd help.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums