Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!nnews!cs.utexas.edu!asuvax!stjhmc!p88.f15.n300.z1.fidonet.org!Lawson.English From: Lawson.English@p88.f15.n300.z1.fidonet.org (Lawson English) Newsgroups: comp.sys.mac.programmer Subject: What am I doing wrong?--modal dialog use crashes Message-ID: <10529.282956F5@stjhmc.fidonet.org> Date: 9 May 91 00:53:17 GMT Sender: ufgate@stjhmc.fidonet.org (newsout1.26) Organization: FidoNet node 1:300/15.88 - Tucson Apple Core, Tucson AZ Lines: 188 Willy S. Liao writes in a message to All WSL> OK dokee, I have a problem that's driving me nuts. I'm sure WSL> I'm doing something wrong, but I don't know what it is...I'm WSL> using THINK C 4.04 with System 7.0f4 and the Think Class Library The Think Class Libraries don't support dialogs directly (gDeskTop gets confused and tries to send messages to the dialog window after it is gone). The following class is based on the information supplied by Symantec Tech Support. The key procedures are: DeactivateTCLDeskAndShowDialog; and ActivateTCLDeskAfterHideDialog; which will prevent gDeskTop from getting an update while the dialog is around. One does "myDialog.IResModalDialog (aDLOGid, aFilter, aDefaultItem);" followed by "myDialog.Go" (for generics) or "Run" (for more complicated dialogs) and overrides the "DoModalDialogStuff" method to do the inner workings. Caveat: only one ModalDialog should be "GO"-ing at a time...otherwise gDeskTop might get confused. Never tried it with multiple dialogs, maybe it will work... Hope it helps, source code released for public use by Lawson D. English. ****************************************************************************** {*****************************************************************************} {** CModalDialog implements a generic Modal Dialog Class **} {** Copyright 1991 Lawson D. English (use at will but remember me as well) **} {** From Symantec Tech Support suggestions. **} {**} {*****************************************************************************} unit CModalDialog; interface uses TCL, DialogIntf; implementation {**} { * IModalDialog} { *} { *Initialize a ModalDialog object.} { *} { **} procedure CModalDialog.IModalDialog (aFilter: procPtr; aDefaultItem: Integer); begin itsDefaultItem := aDefaultItem; itsFilterProc := aFilter; { you would have to override here to create dialogs on-the-fly } end; { * IResModalDialog * } { *} { *Initialize a ModalDialog object using a resource * } { * } { ** } procedure CModalDialog.IResModalDialog (aDLOGid: Integer; aFilter: procPtr; aDefaultItem: Integer); begin itsDLOGid := aDLOGid; IModalDialog (aFilter, aDefaultItem); end; procedure CModalDialog.free; begin DisposDialog(itsDialogPtr); inherited Free; end; procedure CModalDialog.ProcureDialogPtr; var theDLOGid: Integer; begin theDLOGid := itsDLOGid; { a dialog must always be invisible when gotten } { to avoid sending updates to gDeskTop, hence "WindowPtr(0)"} itsDialogPtr := GetNewDialog(theDLOGid, nil, WindowPtr(0)); end; procedure CModalDialog.DeactivateTCLDeskAndShowDialog; var theDialogPtr: DialogPtr; begin theDialogPtr := itsDialogPtr; gDeskTop.Deactivate; { we can't have gDeskTop active when } BringToFront(theDialogPtr); { the dialog comes to the front } ShowHide(theDialogPtr, TRUE); end; procedure CModalDialog.ActivateTCLDeskAfterHideDialog; var theDialogPtr: DialogPtr; begin theDialogPtr := itsDialogPtr; ShowHide(theDialogPtr, FALSE); SendBehind(theDialogPtr, WindowPtr(0)); { Hide the dialog before gDeskTop } gDeskTop.Activate; { is activated } end; {**} { * SetDialogID} { *} { *For those times when you need to have a generic dialog with various IDs} { * and just say "Go"} { **} procedure CModalDialog.SetDialogID (aDLOGid: integer); begin itsDLOGid := aDLOGid; end; {**} { * Go * } { *} { *Generic RUN using defaults of no procPtr and itemHit of 1 for RETURN * } { * } { ** } procedure CModalDialog.Go; begin itsDefaultItem := 1; { implements the generic "RETURN" default dialog} itsFilterProc := nil; { with no filterProc } RunModalDialog; free; end; {**} { * RunModalDialog} { *} { *Run ModalDialog object... NO! REally?} { *} { **} procedure CModalDialog.RunModalDialog; var theDialogItem: Integer; theFilterProc: ProcPtr; theDLOGid: Integer; begin theFilterProc := itsFilterProc; ProcureDialogPtr; DeactivateTCLDeskAndShowDialog; repeat ModalDialog(theFilterProc, theDialogItem); DoModalDialogStuff(theDialogItem); until (theDialogItem = itsDefaultItem); ActivateTCLDeskAfterHideDialog; end; procedure CModalDialog.DoModalDialogStuff(theDialogItem:Integer); begin { needs to be overriden in your own dialog classe } end; end. end. ******************************************************************************* -- Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!300!15.88!Lawson.English Internet: Lawson.English@p88.f15.n300.z1.fidonet.org