[comp.sys.mac.programmer] Dialog Problems

jmh@ns.network.com (1606) (06/03/89)

I attempted to mail this to Tim, but my mailer can not find
tim@hoptoad.uucp, so I am posting this.

Thank you for taking the time to respond. I appreciate your
suggestion that I need a DisposDialog rather than a CloseDialog
(yes, I pass NIL for the space to GetNewDialog).  Unfortunately,
that is actually what I do.

Yes, I know that mopre accurate and complete information would
make it easier to help out.  Unfortunately, the code is on the MAC
at home, and I am composing mail/news at work.  Thus, I have to write
down the code at home, and rekey it at work.  I make some typos.

To answer the specific question you asked, val is a static int.
The processing code uses a local int variable i:

	for (i = 1; i <= strbuf[0]; i++) {
		if (strbuf[i] < '0' || strbuf[i] > '9') break;
		val = val*10 + strbuf[i] - '0';
	}

For completeneww, the routine begins by copying val to a local
variable, and if the user clicks cancel, val is restored to
its initial value.  Otherwise, if ok or return was hit,  I do
some calculations to select a spot in the main window.

Yes, I did not use proper internationalization or strs/str#
resources.  This is a simple program for my own use.
While I have been a programmer for a long time (I am the in house
consultant to the software development organization and reasonably 
fluent in C unix), this is only the second Macintosh program I have
ever written.

While I appreciate any assistance you can give me, please lighten
up just a litttle in the accusatory tone.

Thanks,
Joel M. Halpern			jmh@nsco.network.com
Network Systems Corporation	612 - 424 - 1606

tim@hoptoad.uucp (Tim Maroney) (06/05/89)

It's pretty clear that all the code posted has been correct.  I'd like to
mention a few debugging techniques that can be useful in this kind of
situation:

(1)  Brute force.  Cut out small sections of code that are not
absolutely neccessary to correct execution of the software (e.g.,
number processing) and then try to replicate the problem.  Delete only
one small section each time, or cut out a large section until you find
the area of the problem, then narrow it down from there.

(2)  Check for heap corruption using MacsBug.  Break on ModalDialog and
check at that time, the second time around; also, checking after the
first CloseDialog would make sense.  The command is "HC".  If the heap
is corrupted, using the ATHC command will locate the place in short
order.

(3)  Make a tiny application consisting solely of initializing the
managers and then going into your dialog.  Be sure to use exactly the
same code and resources.  If you can run it more than once in the tiny
application (Just stick it in a loop) then your problem is actually in
another section of code and it only happens to blow away that dialog
through coincidence.

(4)  Use RezDet to check the resource fork of your application.

(5)  Step into the ROM call ModalDialog to find out exactly where the
crash happens.  This can be painful but may be neccessary.

(6)  Run in Heap Scramble mode and see if anything breaks.  If so, go
to your code and figure out why.

Good luck!
-- 
Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim
"There's a real world out there, with real people.  Go out and play there for
 a while and give the Usenet sandbox a rest.  It will lower your stress
 levels and make the world a happier place for us all." -- Gene Spafford

jon@wehi.dn.mu.oz (Jon Eaves) (07/17/89)

Hi Net,

  I have a very small problem, but I have no idea how to fix it.

I created a DLOG and associated DITL in ResEdit (thanks Luke), and ResEdit
displays the DLOG with the DITL list properly.  There are 6 items.  The
first two are buttons and the rest are static/editable text.

I have a trivial program based on the below : (written in LSC 3.01)

main()
{
  InitStuff();
  OpenResFile("\pRFile.rsrc");
  myDialog=GetNewDialog(myDLOGref,0,-1);
}

The dialog gets drawn on the screen, but only the first two items are drawn
in it????? ( the OK/Cancel buttons ).

What's wrong?, Have I fallen into 'Trap for Beginners #1 of 999'

--------------------------------------------------------------------------------
  Jon Eaves                Walter and Eliza Hall Institute for Medical Research.
               It's never too late to learn,
               but we sometimes learn when it's too late.

ACSnet    ( jon@wehi.dn.mu.oz )    
UUCP      ( uunet!munnari!wehi.dn.mu.oz!jon )
Internet  ( jon%wehi.dn.mu.oz@uunet.uu.net )
--------------------------------------------------------------------------------

kazim@Apple.COM (Alex Kazim) (07/19/89)

In article <331@wehi.dn.mu.oz> jon@wehi.dn.mu.oz (Jon Eaves) writes:
>
>main()
>{
>  InitStuff();
>  OpenResFile("\pRFile.rsrc");
>  myDialog=GetNewDialog(myDLOGref,0,-1);
>}
>
>The dialog gets drawn on the screen, but only the first two items are drawn
>in it????? ( the OK/Cancel buttons ).
>
>What's wrong?, Have I fallen into 'Trap for Beginners #1 of 999'
>

Yup.  Trap # 1.
You need to call DrawDialog() (Inside Mac Vol 1) to display the items.

Since your dialog has buttons, you probably want to call ModalDialog()
to handle the events.  In this case, you don't need to call DrawDialog()
as ModalDialog() does this for you.

=========================================================================
Alex Kazim, Apple Computer
Mac Programming: Come on baby, make it hurt so good...
=========================================================================

sdh@wind.bellcore.com (Stephen D Hawley) (07/19/89)

>main()
>{
>  InitStuff();
>  OpenResFile("\pRFile.rsrc");
>  myDialog=GetNewDialog(myDLOGref,0,-1);
>}
>
>The dialog gets drawn on the screen, but only the first two items are drawn
>in it????? ( the OK/Cancel buttons ).
>
>What's wrong?, Have I fallen into 'Trap for Beginners #1 of 999'

if the dialog box is modal, you have to call DrawDialog(), I believe to get
it to show up.

If it is a modelss dialog box, it will be drawn when you have you event loop
all patched together.  When a dialog box is called up with GetNewDialog(),
only some of the items are drawn, the rest are taken care of by an update
event that is generated.  If you have the IsDialogEvent() text and
DialogSelect(), the rest will be drawn auto-magically.

clear?

Steve Hawley
sdh@flash.bellcore.com


"1) Never get involved in a land war in Asia and 2) Never go in with a
Sicilian when death is on the line."

jon@wehi.dn.mu.oz (Jon Eaves) (07/20/89)

In article <17225@bellcore.bellcore.com>, sdh@wind.bellcore.com (Stephen D Hawley) writes:
>>main()
>>{
>>  InitStuff();
>>  OpenResFile("\pRFile.rsrc");
>>  myDialog=GetNewDialog(myDLOGref,0,-1);
>>}
>>
>>The dialog gets drawn on the screen, but only the first two items are drawn
>>in it????? ( the OK/Cancel buttons ).
>>
>>What's wrong?, Have I fallen into 'Trap for Beginners #1 of 999'
> 
> if the dialog box is modal, you have to call DrawDialog(), I believe to get
> it to show up.
> 
> If it is a modelss dialog box, it will be drawn when you have you event loop
> all patched together.  When a dialog box is called up with GetNewDialog(),
> only some of the items are drawn, the rest are taken care of by an update
> event that is generated.  If you have the IsDialogEvent() text and
> DialogSelect(), the rest will be drawn auto-magically.
> 
> clear?
> 
Yup, thanks to all who replied. I was trying to get things working a bit
at a time. ie. #1 -> draw the box, #2 -> process events for the box.

However #1 and #2 are a little more closely tied than that.

I have now the above code +
for (;;) {
  ModalDialog(NIL,&itemHit);
  process(itemHit);
}

and it all works nicely.

--------------------------------------------------------------------------------
  Jon Eaves                Walter and Eliza Hall Institute for Medical Research.
               "I have this feeling, my luck is not too good,
                this sword here at my side don't act the way it should" - BOC

ACSnet    ( jon@wehi.dn.mu.oz )    
UUCP      ( uunet!munnari!wehi.dn.mu.oz!jon )
Internet  ( jon%wehi.dn.mu.oz@uunet.uu.net )
--------------------------------------------------------------------------------