Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!van-bc!rsoft!mindlink!a347 From: a347@mindlink.UUCP (John Miller) Newsgroups: comp.sys.mac.programmer Subject: Re: Problem at closeDev Message-ID: <3240@mindlink.UUCP> Date: 19 Sep 90 14:18:50 GMT Organization: MIND LINK! - British Columbia, Canada Lines: 76 Pete Resnick writes > I have a routine that updates a resource according to what's in an > editText box in my cdev. I call the routine when the OK button is > hit and when the cdev gets closed. On the hitDev, everything works > just ducky. I call the routine, passing it CPDialog, a handle to my > data (I do it the old fashioned way), and numItems. I check each to > make sure they have valid values entering the routine. They are all > constant on entering. Then I do a GetDItem for the editText box. > Boom. The value returned in the item Handle when I am on the hitDev > is some longword. On the closeDev, I get a 0. Now, I don't know for > sure that all the values in CPDialog and my data handle are correct > (doing that in Macsbug would've been ugly), but I am sure numItems > has not changed and the actual value of CPDialog and my data handle > are perfectly constant. Do the dialog items disappear before the > closeDev (that would be very bad, and unlikely since I have seen other > cdevs check data on the close), or am I doing something stupid? The dialog items do indeed disappear before the closeDev message, and yes, it is very bad. Of course, the items don't always disappear before the closeDev. If the user causes the closeDev to occur by closing the Control Panel window, the items are still there. When the closeDev is caused by the user clicking on another cdev icon, that's when the Control Panel graciously removes the items before sending closeDev to your cdev. Of course, the fact that it works in a desirable fashion some of the time isn't much help to you. The best thing to do is to update your stored information whenever a change is made to the text edit item. You do this by passing any keystrokes directly to the Dialog Manager and then turn them into null events so that the Control Panel will ignore them. Your routines that handle the editing commands should also update the stored information whenever the user uses one of the edit commands. Then on the closeDev command, your code looks only at values stored in your private cdev storage; it does not look at anything in the dialog item list. Here is a crude fragment of what to: case keyEvtDev: /* respond to keydown */ /* I stripped out the code that directs cut/copy/paste commands to the appropriate routine and that also rejects other command-key combinations. */ /* UpdateSavedValues() is a routine in your code that extracts the information from the dialog and saves it in your private data structure. */ DialogSelect(theEvent, &CPDialog, &dummyItemHit); UpdateSavedValues(cdevStorage, CPDialog, numItems); theEvent->what = nullEvent; /* Hide the key event from the control panel. */ break; This design flaw appears in at least 2 versions of the 6.0.x system software, so I guess we are all stuck with it. It is unfortunate because it makes cdev code more complicated than it has to be. I find a worrisome parallel between this design flaw and the startup/openStack message ordering problem that Apple fixes in HyperCard 2.0. (I'd include good old DragGrayRgn() as well, but that is rather old news.) I don't know what type of internal design checklists Apple may have, but I would hope that they could be strengthened to better check for these types of issue. Apple should also consider updating its DTS TextEdit cdev example code. The current version is misleading: it doesn't include any code that handles the closeDev problem. ---------------------------------------------------------------------- John Miller (604) 433-1795 Symplex Systems AppleLink (rarely) CDA0461 Burnaby, British Columbia Fax: (604) 430-8516 Canada Internet: john_miller@mindlink.uucp ----------------------------------------------------------------------