Coerce String to Handler? - SOLVED!!!
Coerce String to Handler? - SOLVED!!!
- Subject: Coerce String to Handler? - SOLVED!!!
- From: "Neal A. Crocker" <email@hidden>
- Date: Wed, 18 Apr 2001 01:03:19 -0500
Ok, here the problem:
Subject: Coerce String to Handler?
To: <email@hidden>
From: Ehsan Saffari <email@hidden>
Date: Fri, 13 Apr 2001 08:53:54 -0600
Hi
Is it possible to coerce a string to a handler name
so the handler can be executed?
set x to "iac"
my handler x()
--> Can't make "iac" into a handler.
on iac()
beep
end iac
cheers
ehsan
Now, here are the the solutions. The first solution allows a script
to "coerce" a string to a reference to a handler whose name is given
by the string. It works for a handler of a compiled script. If you
want to apply it to a script application, the script which uses this
solution must use the "load script" command and apply this solution
to the result. The second solution allows a script to call a handler
in a script application by name, using a string to specify the name
and a list to pass the argument.
!!!!!! Both solutions contain lines with attached comments saying
the line will not compile. Such lines are simply the result of a
transformation which ocurrs when the original line (shown above each
uncompilable line as a commented line) is compiled. In order to
comilple the script examples below, you must delete the lines which
will not compile and replace each one with the line above it. You
must, of course, uncomment the replacement line. !!!!!!
!!!!!! In the script examples below, the character combinations "<<"
and ">>" are used to represent the chevron characters given by
Option-\ and Shift-Option-\ !!!!!!
First solution, for handlers of compiled scripts. In the example
below, a reference to handler "add1" of script "me" is produce and
then use to call the handler:
-- start of script
on makehandlerreference(propname, target)
script refscript
--{class:reference,<<class form>>:<<constant
****usrp>>, <<class want>>:<<class prop>>, <<class seld>>:propname,
<<class from>>:target}
{class:reference, <<class form>>:<<constant
****usrp>>, <<class want>>:property, <<class seld>>:propname,