Dispose(Dialog,Done) Problem (BP)

Dispose(Dialog,Done) Problem (BP)

Post by Jesse L. The » Fri, 24 Sep 1993 12:18:32



I think I am clearly missing some silly thing
while disposing a modeless dialog box.

My problem is that I create a Procedure to
Initialize the dialog box, and I dispose it
in the Application's HandleEvent. The computer
crashes in real mode and gives a 216 error in
protected mode (I know all about this error so
lets concentrate on the problem).

If I dispose the dialog in the procedure
that created it, I have no such problem.

The part of the code I am interested is attached.
The routine is called
PresentDataSet(Var Dialog : PDialog, DataSetName : String);
The Option to close the Dialog in the HandleEvent is
cmDiag17.

Can someone give a clue of where my problem is ?

Thanks,

Jesse

Procedure PresentDataSet(Var Dialog : PDialog; DataSetName : String);
{ The PresentDataSet Places the Data Set Name in a small modeless Diag     }
{ Note Dispose of the Present Dialog HAS TO BE done in the calling program }
{ ------------------------------------------------------------------------ }
const H=5;
      W=30;       {H and W Refers to Size of Dialog Box}
Var
  R     : TRect;
  Init1, End1 : Integer;
  Center, Ld2 : Integer;
Begin

{ Initialize the Modeless Dialog Box}
  R.Assign(0, 0, W, H);
  Dialog := New(PDIALOG, Init(R, 'Present Data Set'));
  Dialog^.Options := Dialog^.Options or ofCentered;

{ Construct the Internal Parts in the Dialog}
  With Dialog^ do
  Begin

{Insert Name}
     Center := W div 2;
     Ld2    := (length(DataSetName) +1 )  div 2 ;
     R.Assign( Center - Ld2, H-3, Center + Ld2+1, H-1);
     Insert(New(PStaticText, Init(R, DataSetName)));

  End; {with dialog}

  DeskTop^.Insert(Dialog);

  {Dispose(Dialog, Done);}
{^^^^^^^^^^^^^^^^^^^^^^^}
{I have no problems here}

End; {PresentDataSet}
{ ------------------------------------------------------------------------ }

PROCEDURE TRApp.HandleEvent(VAR Event : TEvent);
Var
  MsgBack : Word;
  PDSDialog: PDIALOG;

BEGIN

  MsgBack := 0;

    TApplication.HandleEvent(Event);
    IF Event.What = evCommand THEN BEGIN
        CASE Event.Command OF
          cmDiag1 : Begin UnitSysParsDiag(MsgBack); End;
          cmDiag6 : Begin
                      LNAquifParsDiag(MsgBack);;
                    End;
          cmDiag7 : Begin
                      LHAquifParsDiag(MsgBack);;
                    End;
          cmDiag15: Begin
                      Reset_Default_Colors;
                    End;
          cmDiag16: Begin
{I generate the dialog box here}
                       PresentDataSet(PDSDialog,' Test ');
                    End;
          cmDiag17: Begin
{ I dispose the dialog box here }
{                       If PDSDialog <> Nil Then Dispose(PDSDialog, Done);}
                       PDSDialog^.Done;
                    {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
                    { None of the two above alternatives work }
                    End;
        ELSE
          Exit;
        END;
        ClearEvent(Event);
    END;
END; {HandleEvent}
{ ------------------------------------------------------------------------ }

 
 
 

Dispose(Dialog,Done) Problem (BP)

Post by p.. » Sat, 25 Sep 1993 10:10:54


Quote:>I think I am clearly missing some silly thing
>while disposing a modeless dialog box.

>My problem is that I create a Procedure to
>Initialize the dialog box, and I dispose it
>in the Application's HandleEvent. The computer
>crashes ....

You said it gives a 216 GPE error in Protected Mode.
But it probably gives a 210 object not initialized
error in Real Mode, right?  That's what my simulations
of your code show.

Quote:>If I dispose the dialog in the procedure
>that created it, I have no such problem.
>[...]
>Begin
>{ Initialize the Modeless Dialog Box}
>  R.Assign(0, 0, W, H);
>  Dialog := New(PDIALOG, Init(R, 'Present Data Set'));
>  Dialog^.Options := Dialog^.Options or ofCentered;

>{ Construct the Internal Parts in the Dialog}
>  With Dialog^ do
>  Begin
>     {Insert Name}
>     Center := W div 2;
>     Ld2    := (length(DataSetName) +1 )  div 2 ;
>     R.Assign( Center - Ld2, H-3, Center + Ld2+1, H-1);

                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Say what?  Why do you avoid using the "ofCenterX" option here?
Rather you should state:

      R.Assign(0,H-3, succ(length(DataSetName)), pred(H));

Quote:>     Insert(New(PStaticText, Init(R, DataSetName)));
>  End; {with dialog}

>  DeskTop^.Insert(Dialog);

>  {Dispose(Dialog, Done);}
>{^^^^^^^^^^^^^^^^^^^^^^^}
>{I have no problems here}

Notice that you don't create a situation where you don't
precisely know whether Dialog is initialized.  Later you
check whether Dialog <> nil but please refer to the language
reference manual concerning "Dispose()".  After returning
from "Dispose()" the value of the object parameter passed
to it is ***not*** nil, but rather ***undefined***.

- Show quoted text -

Quote:>End; {PresentDataSet}
>{ ------------------------------------------------------------------------ }

>PROCEDURE TRApp.HandleEvent(VAR Event : TEvent);
>Var
>  MsgBack : Word;
>  PDSDialog: PDIALOG;

>BEGIN

>  MsgBack := 0;

>    TApplication.HandleEvent(Event);
>    IF Event.What = evCommand THEN BEGIN
>        CASE Event.Command OF
>          cmDiag1 : Begin UnitSysParsDiag(MsgBack); End;

           ^^^^^^^
Say what?

Quote:>          cmDiag6 : Begin

           ^^^^^^^
Say what, again?  These numbers mean something?  Really?
The beauty of modern languages is that they allow rather
descriptive names; good programming practice ***demands***
that you use descriptive names, primarily because you
won't be the one maintaining your programs.  Some other poor
hack will.

- Show quoted text -

Quote:>                      LNAquifParsDiag(MsgBack);;
>                    End;
>          cmDiag7 : Begin
>                      LHAquifParsDiag(MsgBack);;
>                    End;
>          cmDiag15: Begin
>                      Reset_Default_Colors;
>                    End;
>          cmDiag16: Begin
>{I generate the dialog box here}
>                       PresentDataSet(PDSDialog,' Test ');
>                    End;
>          cmDiag17: Begin
>{ I dispose the dialog box here }
>{                       If PDSDialog <> Nil Then Dispose(PDSDialog, Done);}
>                       PDSDialog^.Done;
>                    {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
>                    { None of the two above alternatives work }

Here, your test for "PDSDialog <> nil" is meaningless.  It would
appear that an action elsewhere is invalidating the value of
"PDSDialog".  If you've forgotten to comment out the "Dispose()"
statement in the init'ing procedure, you would have a problem.
You'll have to set some breakpoints and find out where it is
you're going astray.

Perhaps the easiest way to handle this is to send a message to
the dialog box that it will recognize, that is "cmClose".  This
only works if the non-modal dialog box is the topmost active
dialog box.

It's also a good idea to "DeskTop^.Delete(PDSDialog)" as well
before disposing of it.  (Remember, you've inserted the dialog
box as a subview of DeskTop, so you should properly tell
the DeskTop to delete it from its subview list.)

If it's not, create a descendent and override the HandleEvent()
method to listen to "cmNonModalClose" or something like that. If
there's to be more than one non-modal dialog box, then you have
to distinguish between them, perhaps by a numbering system.  Once
the message "cmNonModalClose" is received, it is converted to
"cmClose".

Perhaps someone will see something else which I missed.

PF

 
 
 

Dispose(Dialog,Done) Problem (BP)

Post by Berend de Bo » Sat, 25 Sep 1993 07:11:02


Jesse L. The' wrote in a message to All:


JLT> PROCEDURE TRApp.HandleEvent(VAR Event : TEvent);
JLT> Var
JLT>   MsgBack : Word;
JLT>   PDSDialog: PDIALOG;

Change this to:

const
  PDSDialog:PDialog = nil;

and everything should work. Remember: local vars are ?? after exiting a
procedure. You assume that it is still valid.

Groetjes,

Berend (-:
fido: 2:281/527.23

 
 
 

1. Disposing of dialog box

I am currently developing a Pascal Turbo Vision application in which a
TDialog is executed involving some TInputLines and two Buttons: Ok and
Cancel.  These buttons call events which are handled by the dialog's event
handler.  After the events are executed, I want the dialog to disappear (but
not using Hide).  I've tried calling Done from the event handler but it only
locks up the program.  Is there a way to remove the dialog from inside the
event handler, or am I going about this the wrong way?

Help!

"In God we trust.  The rest we prosecute."

2. socket

3. BP:frameless dialog box?

4. Help! determining datatype at parse-time w/ XML Schemas

5. Free TV Dialog Box Script Compiler for TP/BP 7.0+

6. CSSCGC2001

7. problem disposing object

8. FW: Executing a dialog from a dialog

9. Executing a dialog from a dialog

10. Executing a dialog from inside a dialog

11. Dialog from a dialog?

12. Open a Dialog in a Dialog