Path: utzoo!utgpu!news-server.csri.toronto.edu!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: Re: Neuron Data's Open Interface Message-ID: <14492.28619076@stjhmc.fidonet.org> Date: 21 Jun 91 05:11:51 GMT Sender: ufgate@stjhmc.fidonet.org (newsout1.26) Organization: FidoNet node 1:300/15.88 - Tucson Apple Core, Tucson AZ Lines: 209 Gerrard Aissing writes in a message to All GA> Hi! GA> I am new to Mac programming. I try to use the Think-C TCL to GA> create an application. At a certain point I want to use a dialog GA> to enter some data. After closing the dialog, the program crashes GA> in DoDeactivate(). There does not seem to be a Class for Modal GA> dialogs in TCL, bu using the standard routines seems to couse GA> a crash? So what should I do? Does anyone have experience in GA> implementing a class for modal dialogs? GA> Thanks. I'm sorry that I have no way of uploading this to one of the regular sites, as it makes me the resident "guru" on the subject. The TCL's don't handle dialogs correctly. If you notice, when your program has no windows on the screen, there should be no problem. When you have a window up, the TCL's somehow think that the Dialog window is part of gDeskTop's window list, and try to send it messags as it goes away... The following code is based on Symantec tech support's suggestions: The guts are the two follwing methods that deactivate the gDsktop before showing the dialog, and reactivating it afterwards. procedure CModalDialog.DeactivateTCLDeskAndShowDialog; var theDialogPtr: DialogPtr; begin theDialogPtr := itsDialogPtr; gDeskTop.Deactivate; BringToFront(theDialogPtr); ShowHide(theDialogPtr, TRUE); end; procedure CModalDialog.ActivateTCLDeskAfterHideDialog; var theDialogPtr: DialogPtr; begin theDialogPtr := itsDialogPtr; ShowHide(theDialogPtr, FALSE); SendBehind(theDialogPtr, WindowPtr(0)); gDeskTop.Activate; end; Below is my dialog class in all of its glory. CDialog is of type CObject. itsDefaultItem is of type integer. itsFilterProc is a procPtr. itsDLOGid is an integer. itsDialogPtr is a DialogPtr. You use the thing by evoking it with either ".Go" or ".Run" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + { Copyright 1990 Lawson D. English } { Use freely, but remember where you got it when you become a hiring manager } unit CModalDialog; interface uses TCL, DialogIntf; implementation {**} { * IModalDialog} { *} { *Initialize a ModalDialog object.} { *} { **} procedure CModalDialog.IModalDialog (aFilter: procPtr; aDefaultItem: Integer); begin itsDefaultItem := aDefaultItem; itsFilterProc := aFilter; end; { * IResModalDialog * } { *} { *Initialize a ModalDialog object using a resource * } { * } { ** } procedure CModalDialog.IResModalDialog (aDLOGid: Integer; aFilter: procPtr; aDefaultItem: Integer); begin itsDLOGid := aDLOGid;{ is there ever a reason to need the ID while running ?} itsFilterProc := aFilter; itsDefaultItem := aDefaultItem; end; procedure CModalDialog.free; begin DisposDialog(itsDialogPtr); inherited free; end; procedure CModalDialog.ProcureDialogPtr; var theDLOGid: Integer; begin theDLOGid := itsDLOGid; itsDialogPtr := GetNewDialog(theDLOGid, nil, WindowPtr(0));{ a dialog must always be ionvisible when gotten } end; procedure CModalDialog.DeactivateTCLDeskAndShowDialog; var theDialogPtr: DialogPtr; begin theDialogPtr := itsDialogPtr; gDeskTop.Deactivate; BringToFront(theDialogPtr); ShowHide(theDialogPtr, TRUE); end; procedure CModalDialog.ActivateTCLDeskAfterHideDialog; var theDialogPtr: DialogPtr; begin theDialogPtr := itsDialogPtr; ShowHide(theDialogPtr, FALSE); SendBehind(theDialogPtr, WindowPtr(0)); gDeskTop.Activate; end; {**} { * SetDialogID} { *} { *For those times when you need to have a generic dialog with various IDs} { *} { **} procedure CModalDialog.SetDialogID (aDLOGid: integer); begin itsDLOGid := aDLOGid; end; {**} { * Go * } { *} { *Generic RUN * } { * } { ** } procedure CModalDialog.Go; begin itsDefaultItem := 1; itsFilterProc := nil; ProcureDialogPtr; 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(itsFilterProc, theDialogItem); DoModalDialogStuff; until (theDialogItem = itsDefaultItem); ActivateTCLDeskAfterHideDialog; end; procedure CModalDialog.DoModalDialogStuff; begin { override to do the "meat" of the dialog } end; end. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Hope it helps... -- Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!300!15.88!Lawson.English Internet: Lawson.English@p88.f15.n300.z1.fidonet.org