Looks like a bummer
Looks like a bummer
- Subject: Looks like a bummer
- From: Richard 23 <email@hidden>
- Date: Wed, 13 Dec 2000 21:45:42 -0800
Is it possible for a script applet to modify a record passed to it,
with the modification reflected in the caller?
I've come to the conclusion that it's not which is a bit of a drag.
When you call a handler passing it a variable which contains a list
or record, it is passed by reference, the result of which is that any
changes made to the list or a record during the handler's execution
are reflected in the caller's variable. This means the list or record
is modified in place without an additional copy being made and you
don't need to then set the variable to the result in order for it to
"stick."
This doesn't seem to be the case when a script running in an editor
calls a handler in a running applet, although it does if you use
load script and call the script's handler from there.
Here's a quickie try-at-home example:
Stay-Open Applet:
----------
on Test(theObj)
set theObj's flag to "bar"
end Test
----------
Save it as a stay open applet, giving it the name "FlagTest"
Then run it so the tell block in the following will work:
----------
property Test_Prop: {flag: "foo"}
tell application "FlagTest" to Test(Test_Prop)
copy Test_Prop to appletValue
tell application "Finder" to set theFile to file of process "FlagTest"
set theObj to load script theFile
tell theObj to Test(Test_Prop)
return {appletValue, scriptValue}
--> {{flag:"foo"}, {flag:"bar"}}
----------
The result is that the applet didn't modify the value. Why not?
Kinda puts a crimp in my plans for world domination. Perhaps an
evil genius and explain why and help me solidify my plans to take
over the world....
Thanks,
R23