pb in delete TGTextEntry

From: Olivier Meplan (meplan@isn.in2p3.fr)
Date: Tue Oct 19 1999 - 18:02:05 MEST


Hi Rooters!
I have a pb in my GUI interface...I describe the pb in a preceding
e-mail (subject:RootX11ErrorHandler);
Valery Onuchin (Thank you again) try to help me and he sent me a small
code that is working on his computer but not on my (I am running on a
DEC XP100 with cxx 6.). Because I sure that I doing something wrong but
I don't know where I send you a sample code wich crashes in the
destructor of "Test" in when I try to delete the TGTextEntry (just
between the 2 "cout").
Thank you for your Help,
Best regards
Olivier
//-----------------------------------------------------
//panel.h:
//-------------------------------------------------------
#include <TROOT.h>
#include <TApplication.h>
#include <TVirtualX.h>
#include <TGFrame.h>
#include "TGLayout.h"
#include <TGButton.h>
#include <TGMsgBox.h>
#include <TGTextEntry.h>
#include <TGTextBuffer.h>
#include <TGLabel.h>
#include "TObjString.h"

#include <iostream.h>

class MainWin: public  TGMainFrame
{
  private :
 TGTextButton  *fButtonOk,*fButtonExit;
        TGCompositeFrame *fGF0,*fF1;

  public :
 MainWin(const TGWindow *p);
 ~MainWin(); // destructeur
 Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
 void CloseWindow();

        ClassDef(MainWin,1)
};


class Test: public  TGTransientFrame
{
  private:
        TGCompositeFrame     *fS0;
        TGCompositeFrame     *fSH1,*fSH2;
        TGTextButton         *fBOK;
        TGLayoutHints        *fL10;
        TGTextEntry          *TEName;


  public :
         Test(const TGWindow *p, const TGWindow *main,
                     UInt_t w,UInt_t h, UInt_t options =
kVerticalFrame);

         ~Test();
         Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
         void CloseWindow(){delete this;}

        ClassDef(Test,0)
};
//-------------------------------------------------
//panel.C
//-------------------------------------------------
#include "panel.h"

ClassImp(MainWin)
ClassImp(Test)

//
//------------------------- MainWin
---------------------------------------
//
MainWin::MainWin(const TGWindow *p) : TGMainFrame(p,500,400)
{

 fGF0 = new TGCompositeFrame(this,100,200,kVerticalFrame);
 TGLayoutHints *fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft |
kLHintsExpandX,2, 2, 2, 2);
        AddFrame(fGF0, fL1);
 //
        // Frame for Ok/exit button
        //
 fF1 = new TGHorizontalFrame(fGF0, 60, 20, kFixedWidth);
 TGLayoutHints *fL2 = new TGLayoutHints(kLHintsBottom | kLHintsRight, 2,
2, 2, 2);
 fGF0->AddFrame(fF1, fL2);

        fButtonOk= new TGTextButton(fF1,"&Ok",1);
 fButtonExit= new TGTextButton(fF1,"E&xit",2);

 fF1->AddFrame(fButtonOk,fL1);
        fF1->AddFrame(fButtonExit,fL1);
        fF1->Resize(150, fButtonExit->GetDefaultHeight());

 fButtonOk->Associate(this);
 fButtonExit->Associate(this);
 //REMAP
 SetWindowName("Flash Analysis");
 MapSubwindows();
 Resize(GetDefaultSize());
 MapWindow();
}
//
//----------------------------------------------------------------------------

//
MainWin::~MainWin()
{
 delete fButtonOk;
 delete fButtonExit;
}
//
//----------------------------------------------------------------------------

//
void MainWin::CloseWindow()
{
 gApplication->Terminate(0);
}
//
//----------------------------------------------------------------------------

//
Bool_t MainWin::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
{
 switch (GET_MSG(msg))
  {
  case kC_COMMAND:
   switch (GET_SUBMSG(msg))
   {
    case kCM_BUTTON:
     switch (parm1)
                                 {
                                 case 1:
                                         new
Test(fClient->GetRoot(),this,200,200);cout<<" "<<endl;
                                         cout<<"main"<<endl;
                                                break;
                                        case 2:
                                         CloseWindow();
                                                break;

                                 }
     break;
   }
 }
 return kTRUE;
}
//
//----------------------------------------------------------------------------

//
Test::Test(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t
h,UInt_t options ):
               TGTransientFrame(p, main, w, h, options)
{

 fS0 = new TGCompositeFrame(this, 500, 200);
 fL10= new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX  , 2,
2, 2, 2);
 AddFrame(fS0, fL10);

 fSH1=new TGHorizontalFrame(fS0, 200, 20);
 fS0->AddFrame(fSH1,fL10);

        TGLabel *fLmsg=new TGLabel(fSH1, new TGString("Name:"));
 fSH1->AddFrame(fLmsg, fL10);
 TGTextBuffer *TBName= new TGTextBuffer(100);
        TEName = new TGTextEntry(fSH1, TBName,1);
 TBName->AddText(0, "nothing");
 TEName->Resize(200, TEName->GetDefaultHeight());
 fSH1->AddFrame(TEName, fL10);
 TEName->Associate(this);
        //
        // Frame for Ok/Cancel button
        //
 fSH2=new TGHorizontalFrame(fS0, 200, 20,kFixedWidth);
        TGLayoutHints *fL11=new TGLayoutHints(kLHintsBottom |
kLHintsRight,2,2,2,2);
 fS0->AddFrame(fSH2,fL11);

        fBOK = new TGTextButton(fSH2, "&Ok",10);
        fSH2->AddFrame(fBOK,fL10);
        fSH2->Resize(50, fBOK->GetDefaultHeight());

 fBOK->Associate(this);
        //
 // REMAP
        //
        Resize(GetDefaultSize());
 Window_t wdum;
 int ax, ay;
 gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
                          ((TGFrame *) main)->GetWidth()/2,
                          (((TGFrame *) main)->GetHeight() -
fHeight/2),ax, ay, wdum);
 Move(ax, ay);
 SetWindowName("New Histo Name");
 MapSubwindows();
 MapWindow();
 fClient->WaitFor(this);
}
//
//----------------------------------------------------------------------------

//
Test::~Test()
{
        cout<<"Enter in the Delete"<<endl;
        delete TEName;
        cout<<"TGTextEntry is deleted"<<endl;
        delete fBOK ;
        delete fSH2;
        delete fSH1;
        delete fS0 ;
        delete fL10 ;
}
//
//----------------------------------------------------------------------------

//
Bool_t Test::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
{
 switch (GET_MSG(msg))
 {
  case kC_COMMAND:
   switch (GET_SUBMSG(msg))
   {
               case kCM_BUTTON:
                                switch (parm1)
                                {

     case 10:
                                         cout<<"OK pressed"<<endl;

cout<<TEName->GetText()<<endl;
                                                CloseWindow();
                                                break;
                                }
                 break;
   }
        }
 return kTRUE;
}



--
=========================================================
|Olivier Meplan             |E-mail:meplan@isn.in2p3.fr
|                           |
|ISN, 53 avenue des Martyrs |  Tel +33(0)4 76-28-41-90
|F-38026 GRENOBLE cedex     |  Fax +33(0)4 76-28-40-04
=========================================================



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:41 MET