Re: A reference to problem
Re: A reference to problem
- Subject: Re: A reference to problem
- From: Arthur J Knapp <email@hidden>
- Date: Mon, 04 Jun 2001 13:29:04 -0400
>
Date: Sun, 3 Jun 2001 13:47:08 +0200
>
From: "Serge Belleudy-d'Espinose" <email@hidden>
>
Subject: A reference to problem
>
As seen in the ASLG, I would like to take the benefit of one such construct:
>
> set rxList to a reference to xList
>
>
>
> repeat with i from 1 to 1000
>
> rxList's item i
>
> end repeat
>
But once inside a handler, the line 'rxList's item i' gets me
>
-- Can't get item 1 of xList.
>
Ok, I understand this is a kind of scope problem.
Right.
>
I can use 'global xList' anywhere inside or outside the handler, but this is
>
obviously not what I want.
>
None of the my/of me/'s I tried did work.
>
rxList is 'xList of <<script>>', but I cannot get the class of it. Who is
>
script?
A value created by the "a reference to" syntax creates the reference as
a pointer to a value from some sort of "top level" object, either an
application or a script. <<script>> means literally your script file.
Because of this, your "local" varaibles cannot have references made to
them, because references only refer to variables/properties of applications,
script objects, or to global/properties of the main script.
Take a look at these work-arounds:
on InsideAHandler()
global gList
set gList to {}
set refList to a reference to gList
-- Do stuff with your reference:
repeat with i from 1 to 1000
set refList's end to i
end repeat
repeat with i from 1 to 1000
refList's item i
end repeat
-- Clear the global
set gList to missing value
end InsideAHandler
on YetAnotherIdea()
script TempScript
property tempList : {}
end script
set refList to a reference to tempList of TempScript
-- Do stuff with your reference:
repeat with i from 1 to 1000
set refList's end to i
end repeat
repeat with i from 1 to 1000
refList's item i
end repeat
-- No need to "clear" tempList, because TempScript will
-- disappear when the handler ends
end YetAnotherIdea
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://www.eremita.demon.co.uk/scripting/applescript/