Re: Dynamic Handler Call
Re: Dynamic Handler Call
- Subject: Re: Dynamic Handler Call
- From: has <email@hidden>
- Date: Mon, 10 Apr 2006 00:32:39 +0100
kai wrote:
>Here's a variation, Gary (including parameters):
>
>on handler1(p1, p2)
> display dialog p1 & ", you " & p2 & " chose handler 1."
>end handler1
>
>on handler2(p1, p2)
> display dialog p1 & ", you " & p2 & " chose handler 2."
>end handler2
>
>set hlist to {{searchtext:"text string 1", hname:handler1}, {searchtext:"text string 2", hname:handler2}}
>
>[...]
>
>repeat with h in hlist
> if h's searchtext is chosenText then
> set chosenHandler to h's hname
> exit repeat
> end if
>end repeat
>
>chosenHandler((system info)'s long user name, "wisely")
Note there's a couple of caveats with the above:
1. This is an undocumented (i.e. unofficial) behaviour so there's no guarantee it'll always work. e.g. It contain bugs that'll cause unpredictable behaviour if your code is spread over more than one script [object]. Having to wrap handlers in script objects to pass them around is a bit tedious, but it is the official way to do it.
2. You really need to explicitly declare 'chosenHandler' as a global variable; the above only works because implicitly 'local' variables in a run handler are secretly global than seem to behave more like locals due to AS's weird compile-time binding rules. So while the above demonstration works, it'll break if you put the loose statements into a different handler unless you've got a 'global chosenHandler' declaration at the top.
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden