Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!usc!apple!jdevoto From: jdevoto@Apple.COM (Jeanne A. E. DeVoto) Newsgroups: comp.sys.mac.hypercard Subject: Re: Question about protocol for trapping menu items. Summary: alternative to using a global Message-ID: <48787@apple.Apple.COM> Date: 3 Feb 91 11:31:31 GMT References: <1982taylorj@yvax.byu.edu> <8bdsGB_00WB4E=Yksu@andrew.cmu.edu> Organization: Apple Computer Inc., Cupertino, CA Lines: 64 In article <8bdsGB_00WB4E=Yksu@andrew.cmu.edu> jk3t+@andrew.cmu.edu (Jonathan King)(>) and taylorj@yvax.byu.edu point out a problem with my handler: on doMenu theItem if theItem is "Compact Stack" then close window "MyPalette" send "doMenu Compact Stack" to HyperCard -- avoids recursion palette "MyPalette", "345,80" else pass doMenu end doMenu and more generally with handlers that send their parameters to HyperCard to avoid infinite recursion problems: >> Ok, but what if you're the top stack in the stacksInUse and there's >> another stack below you that also has a doMenu handler that closes >> its windows? If you send the command straight to HyperCard the >> other stacks never get it. > >Yup. I pointed this out, too, in my response to this message. And >the problem isn't just limited to stacks in use; it could occur >anywhere you send a message to Hypercard. But it's a particular >problem when possibly several different handlers along the message >path have to handle a message or Bad Things happen. Here is an improvement. The below is not quite a general case solution, since it won't work in a card script (because doMenu is initially sent to the current card, "the target" will be the same as "me", resulting in passing the doMenu without doing the palette manipulations, if the below handler is in a card's script). However, most handlers of this type are in a background or stack script in any case. on doMenu theItem if theItem is "Compact Stack" then if the target is not the name of me then -- first pass close window "My Palette" send "doMenu Compact Stack" to me palette "My Palette","345,80" else -- second pass pass doMenu end if else pass doMenu end doMenu This avoids the use of a global flag to determine whether the handler has recursed; instead, the message is sent to "me" the first time around, and on the second pass, the target is therefore the same as "me". The handler checks for this and simply passes the message in this case. The message logic looks like this: doMenu (sent as system message when user chooses the menu item) close doMenu (sent to "me" by doMenu handler) pass doMenu up the hierarchy, and afterwards palette (performed by the original doMenu handler) -- ========= jeanne a. e. devoto ======================================== jdevoto@apple.com | You may not distribute this article under a jdevoto@well.sf.ca.us | compilation copyright without my permission. ______________________________________________________________________ Apple Computer and I are not authorized | CI$: 72411,165 to speak for each other. |