[comp.sys.mac.programmer] cdev/Control Panel bug or undocumented action?

buzz@kinetics.UUCP (Mahboud Zabetian) (08/04/88)

I am writing a cdev and noticed a funny behaviour when a closeDev message was
encountered.  It seems as if the value of CPDialog is not valid.  If I do a
GetCtlValue, the item is not found and a bus error occurs.(I do add numItems to
the number of my item).  

For instance, in the following code, a beep is sounded on a deActivDev, but
none for a closeDev:

case closeDev:
	GetDItem(CPDialog, MANBUTTON + numItems, &itemType, &ctrl, &box);
 	if (GetCtlValue(ctrl))
		SysBeep(9);
	TEToScrap();
	cdevValue = 0;
	tcPanel = nill;
	break;
case deActivDev:
	GetDItem(CPDialog, MANBUTTON + numItems, &itemType, &ctrl, &box);
 	if (GetCtlValue(ctrl)) 			 			
		SysBeep(9);

Does anyone know if the closeDev message is supposed to have such a side effect
or whether this is a bug?  Or am I making a mistake?

Thanx.
Standard Disclaimer:  Don't mind me, I'm just babbling.
-------------------------------------------------------------------------------
    Mahboud Zabetian	(415) 256-3702		buzz@kinetics.uucp
     Kinetics, Inc.			...!ucbvax!mtxinu!kinetics!buzz
   2540 Camino Diablo		      ***Coming soon: buzz@kinetics.com !!***
Walnut Creek, CA 94596		     mtxinu!kinetics!buzz@ucbvax.berkeley.edu
-------------------------------------------------------------------------------
   "You may ask yourself, how did I get here?  This isn't my beautiful..."
 							--- Talking Heads
-------------------------------------------------------------------------------

castan@munnari.oz (Jason Castan) (08/08/88)

In article <611@kinetics.UUCP>, buzz@kinetics.UUCP (Mahboud Zabetian) writes:
> I am writing a cdev and noticed a funny behaviour when a closeDev message was
> encountered.  It seems as if the value of CPDialog is not valid.  If I do a
> GetCtlValue, the item is not found and a bus error occurs.(I do add numItems to
> the number of my item).  
> 
> For instance, in the following code, a beep is sounded on a deActivDev, but
> none for a closeDev:
> 
> case closeDev:
> 	GetDItem(CPDialog, MANBUTTON + numItems, &itemType, &ctrl, &box);
>  	if (GetCtlValue(ctrl))
> 		SysBeep(9);

By the time you get the closeDev message, the dialogptr might already have
been disposed. Therefore it is never valid to actually do anything with
CPDialog in 'case closeDev'. What you have to do is check the ctrl value
during nulDev. I got stung by this myself !
	
One last thing about debugging the control panel. Version 3.0 had lots of
subtle bugs that were corrected in 3.3 (?), the latest distributed in release
6.0. Its worth keeping a copy of the old CP if you are writing a cdev, as
i dont think any programmer should be lazy and assume that everyone will be
using the latest system.

	john lim