[comp.sys.mac.programmer] ModalDialog

purcell@sciences.sdsu.edu (Guy B. Purcell) (06/28/90)

I am trying to display an error message in a dialog in a cdev.  The error is
generated when the user closes the cdev with an invalid entry in any of a few
editText items.  I am using the cdev class in THINK C 4.0, with the Close()
method modified for the error check & to save the values if they're ok.

The problem is that, upon my call of ModalDialog() after displaying the error,
a nulDev message is generated.  This causes a *second* call to Close()
(because closeDev message caused status = 0, making the test at the end of
Message() fail).  This second call puts up another error dialog & calls
ModalDialog(), with *no* accompanying nulDev message, and waits for the user.
When the user responds, this second dialog goes away, but the first remains,
hopelessly confusing the Control Panel (the end of the second call to Close()
calls inherited::Close(), which deletes the cdev object, leaving the CP to
deal with the remaining dialog & call to ModalDialog() -- it crashes).  Any
one used ModalDialog() with the cdev class before?  Does it work?  Thanks.
The code:
void	Macbiff_cdev::Close()
{
	/* bunch of tests for valid data */

	if (errCode == noErr)
		/* save the data -- this works fine */
	else
	{
		theErrorWindow = GetNewDialog(ERROR_WIND_ID, NULL, -1);
		/* bunch of code moving the window to CP center & getting
			the error string & putting it into a staticText */
		ShowWindow(theErrorWindow);
		SelectWindow(theErrorWindow);
		ModalDialog(NULL, &temp);
		DisposDialog(theErrorWindow);
		Error(cdevGenErr);
	}
	inherited::Close();
}

Stepping through, all is fine until the ModalDialog() -- there's a slight pause
before execution stops at a breakpoint I have set in Message() (on the switch).
Continuing stepping, it goes to Idle() (from the nulDev) & then to Macbiff_
cdev::Close() (Macbiff_cdev is a subclass of cdev) in the if-then.  Once
again, thanks for the help.

Guy (purcell@zeus.sdsu.edu)