Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!pprg.unm.edu!hc!lanl!opus!ksitze From: ksitze@nmsu.edu (Kevin Sitze) Newsgroups: comp.sys.mac.programmer Subject: Re: Dialog Crash Message-ID: Date: 30 May 89 18:20:16 GMT References: <1415@ns.network.com> Sender: news@nmsu.edu Organization: NMSU Computer Science Lines: 65 In article: Joel writes: >In an application I am attempting to write, I have a dialog with one >edittext item (item 2). When the dialog is requested from the menu, >the routine starts with: > >char strbuf[60]; >GetDItem(dialog, 2, handle); >/* set the string at strbuf+1 to the desired display */ >[s]trbuf[0] = strlen(strbuf+1); >SetIText(handle, strbuf); > >Then I enter a loop: > >do { > ModalDialog(dialog, &theItem); > if (theItem == 2) { > GetDItem(dialog, theItem, handle); > GetIText(handle, strbuf); > /* process input */ > } >} while (theItem != 1 && tehItem != exititem); Your problem lies in an incorrect call to GetDItem as well as a bad call to ModalDialog. You're code should look like this: (Plus some streamlining...) (Changed lines are marked with a '>') >#define NIL (0L) char strbuf[60]; >GetDItem(dialog, 2, &itmKind, &myHandle, &myRect); /* set the string at strbuf+1 to the desired display */ strbuf[0] = strlen(strbuf+1); SetIText(myHandle, strbuf); do { > ModalDialog(NIL, &theItem); /* if (theItem == 2) { > /* the call to GetDItem is not needed here, already */ > /* have info that was needed, namely myHandle. */ > GetIText(myHandle, strbuf); /* process input */ } } while (theItem != 1 && theItem != exitite); I changed your 'handle' variable to 'myHandle' because I program in LSP (which is not case-sensitive) and I don't like seeing 'duplications' between types and variables. (No particular reason...) ModalDialog assumes that the first parameter being passed is a pointer to a filter _function_, NOT a dialog (as you seemed to have done here). This will most probably cause an address error (Error #02 in the SysError dialog box) when you do anything at all with that dialog. I'm surprised that LSC allowed you to compile the above code because ususally it does type-checking on ROM calls (they ARE after all, PASCAL calls) Rich, any ideas? -Kelesi -- +--------------------------------------------------------------------+ | From the Macintosh of: Kevin L. Sitze. This is ME: ksitze@NMSU.edu | +------------------------------------------------------+-------------+ | The difference between intelligence and stupidity is | Is this | | that intelligence has a limit. -- anonymous | better? | +------------------------------------------------------+-------------+