Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling a property by using a string



>What you want is dynamic code evaluation, a.k.a. second-level
>evaluation, which in other languages tends to be embodied by a
>function named "eval".  In AppleScript the only way I know of to do
>this is to call "run script" on a string whose value is the code you
>want to run; unfortunately, such a dynamic script object has no access
>to the variables and properties of the surrounding code, so that won't
>help your particular problem.
> 
> property Average_Test : "Please Don't Work"
> property Good_Test : "Shouldn't Work"
> property Great_Test : "This worked"
> 
> set this to "Great"
> set test to "_Test"
> 
> set thistest to (this & test)
> 
> run script ("my " & thistest)

Some time ago afther a long discussion on accessing records properties by
variable name was condensed in the following code:

to extract_usrf(theRecord, fieldName)
    run script "on run{r}
        return |" & fieldName & "| of r
    end" with parameters {theRecord}
end extract_usrf

Removing the pipes it is possible, to use it to access properties on a
script object like that:

    property Average_Test : "Please Don't Work"
    property Good_Test : "Shouldn't Work"
    property Great_Test : "This worked"

set this to "Great"
set test to "_Test"

set thistest to (this & test)
extract_usrf(me, thistest)

to extract_usrf(theRecord, fieldName)
    run script "on run{r}
        return " & fieldName & " of r
    end" with parameters {theRecord}
end extract_usrf

nino

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.