• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: A reference to problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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/


  • Follow-Ups:
    • Re: A reference to problem (solved)
      • From: "Serge Belleudy-d'Espinose" <email@hidden>
  • Prev by Date: Re: VCard decoder
  • Next by Date: Re: [OFF] Filename encoding on the net
  • Previous by thread: Re: A reference to problem
  • Next by thread: Re: A reference to problem (solved)
  • Index(es):
    • Date
    • Thread