Re: CloseWindow/deleting a frame

Fons Rademakers (Fons.Rademakers@cern.ch)
Tue, 26 May 1998 18:28:46 +0200


Hi Rutger,

this should work:

OTFrame2::CloseWindow()
{
// fParent is pointer to parent OTFrame1
// Maybe parent was closed before child
if (fParent)
fParent->CloseChildWindow(this);
else
delete this;
}

OTFrame1::CloseChildWindow(TGFrame *frame)
{
delete frame;
// find frame pointer in list of OTFrame2's and set to 0
}

Don't call TGMainFrame's CloseWindow because in that case
your window will be destroyed two times (by TGMainFrame::CloseWindow
and by the delete of the OTFrame2).

Cheers, Fons.

Rutger van der Eijk wrote:
>
> Hi all,
>
> I have the following code and problem concerning the use of the GUI:
>
> I have a derived class from TGMainFrame (let's say class OTFrame1), which
> has all kinds of widgets. Pressing one of the buttons creates another
> TGMainFrame derived class (OTFrame2), which from then on should work
> 'stand alone' (i.e. in parallel) with the OTFrame1 frame, until it is
> deleted.
>
> The problem:
>
> I want the window maneger to be able to close OTFrame2 so I need
> to implement the member function CloseWindow(). Here I first call the
> CloseWindow member of the TGMainFrame base-class. But as far as I know
> this does not delete the OTFrame2 object. So how should I do that, and hwo
> do I inform the OTFrame1 object that the OTFrame2 object is deleted?
>
> I tried to do this by calling a member function of the OTFrame1 object
> which deletes it's pointer to the OTFrame2. But becuase this call is done
> from within the OTFrame2 CloseWindow member this (as to be expected) does
> not work proberly. (the object is deleted while the program is still
> executing it)
>
> Is there a way to solve this problem?

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland          Phone: +41 22 7679248
E-Mail: Fons.Rademakers@cern.ch              Fax:   +41 22 7677910