eval
cangelo
21 Jul 2007, 06:02Say 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
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
21 Jul 2007, 10:19You 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:
And to set the value:
So you can use this:
msg <$objectproperty(#tempObj#; #tempProp#)$>
And to set the value:
property <#tempObj#; #tempProp# = some other string>
cangelo
21 Jul 2007, 14:07Perfect. 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?
Of course I hate to depend on obsolete functions in my code/libraries, so what is the future of this functionality?
Alex
21 Jul 2007, 15:59It 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
22 Jul 2007, 00:45Alex 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
24 Jul 2007, 21:12for <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.