• 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
passing handler problems and a resolution
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

passing handler problems and a resolution


  • Subject: passing handler problems and a resolution
  • From: Walter Bushell <email@hidden>
  • Date: Mon, 24 Jan 2011 12:41:28 -0500

I am trying to objectify my code by lists as objects that can be put into lists and then said lists around for processing. After much agony, I found that if I could call a passed handler if and only if the variable was global. Modest example follows:
--------------
on run
	--global xroutine
	global handlerScratch
	set z to 1
	set xroutine to yroutine
	zroutine({xroutine, 5, 7})

end run

to zroutine(myParameter)
	global handlerScratch
	set xroutine to item 1 of myParameter
	set x to item 2 of myParameter
	set y to item 3 of myParameter
	set z to xroutine
	set w to item 1 of myParameter
	log {"z=", z, xroutine, class of xroutine}

	xroutine(x, y)
	log result
	set handlerScratch to w
	handlerScratch(x, y)
	log {"w= ", result}
	z(x, y)
end zroutine

to yroutine(x, y)
	return x + y
end yroutine

-----------------------------
Giving the event log
-------------------------------
(*z=, yroutine, yroutine, handler*)
(*12*)
(*w= , 12*)
tell application "AppleScript Editor"
	z(5, 7)
		--> error number -1708
Result:
error "«script» doesn’t understand the z message." number -1708 from «script»
-------------------------

Which shows that one has to call a passed handler from a global variable ("globalScratch" which is set to "w" in this case), or I suppose a property. Also the
"	set xroutine to yroutine"
line in the run handler apparently makes "xroutine" global or something extra special.

There seems to be little discussion in the documentation about the handler data type. Or am I just oblivious?

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: passing handler problems and a resolution
      • From: Axel Luttgens <email@hidden>
  • Prev by Date: A Lookup Function?
  • Next by Date: Re: getting focus, slow getting icon position in window
  • Previous by thread: Re: A Lookup Function?
  • Next by thread: Re: passing handler problems and a resolution
  • Index(es):
    • Date
    • Thread