Re: Creating list references in handlers. Bad code or bug?
Re: Creating list references in handlers. Bad code or bug?
- Subject: Re: Creating list references in handlers. Bad code or bug?
- From: Helmut Fuchs <email@hidden>
- Date: Fri, 14 Sep 2001 17:50:12 +0200
At 10:26 Uhr -0400 14.09.2001, Victor Yee wrote:
I think that the problem is a matter of scope. References can only
refer to top-level or global varaibles.
Not completely true.
Run this:
on theHandler()
local theData
set theData to {theList:{1, 2, 3}}
set theListReference to a reference to theList of theData
return contents of theListReference
end theHandler
theHandler()
<<
Here, clearly some property of a LOCAL variable is referenced. And it
still works - thanks to the magic of "data sharing".
A reference generated by "a reference to" is simply a description of
how to access an object in AppleEvent terms.
If you ask for "a reference to theData" then a reference is generated
which simply says: look up the object named "theData" in global
scope. This fails.
But there are other references, which are internal to AppleScript.
These are used to achieve the data sharing concept. Such a reference
is automatically included in theListReference above. The reference
from the handler above works like this: look up the property named
"theList" from {theList:{1, 2, 3}}. And this always works!
HTH,
Helmut