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: Victor Yee <email@hidden>
- Date: Fri, 14 Sep 2001 10:26:36 -0400
On Fri, 14 Sep 2001 09:38:33 -0400, Paul Skinner wrote,
>
Can anyone point out my error, or is this a bug?
I think that the problem is a matter of scope. References can only refer to top-level or global varaibles. And remember that variables defined inside handlers are considered local unless explicitly declared as global.
For example:
set theList to {9, 8, 7}
on theHandler()
set theList to {1, 2, 3}
set listReference to a reference to theList
{contents of the listReference, theList}
end theHandler
theHandler()
--> {{9, 8, 7}, {1, 2, 3}}
>
on theHandler()
>
set theList to {1, 2, 3}
>
set listReference to a reference to theList
>
return listReference
>
-->theList of +script;
>
end theHandler
This is the same result as setting a reference at the top-level:
set listReference to a reference to theList
listReference
--> theList of <<script>> (Note that this is the result without "theList" being defined.)
So your error:
>
-->Error -1700: Can't make some data into the expected type.
Is the result of trying to dereference a non-existent variable (remember that references need to point to top-level or global variables and that variables inside handlers are considered local by default).
on theHandler()
global theList
set theList to {1, 2, 3}
set listReference to a reference to theList
{contents of the listReference, theList}
end theHandler
theHandler()
--> {{1, 2, 3}, {1, 2, 3}}
Victor