Re: [ROOT] Bug in TGNumberEntry?

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Mon Dec 10 2001 - 01:36:27 MET


No dtors are needed for those two classes since there is nothing to delete.
Did you try to compile your guiNum.C (.x guiNum.C++)? Does this give
the same error?

Cheers, Fons.


On Sunday 09 December 2001 18:59, cstrato@EUnet.at wrote:
> Dear Rooters
>
> I have created a gui macro displaying a frame containing
> a TGNumberEntry field (see macro guiNum.C below).
>
> Everything works fine, also when I close the gui.
> However, when I want to restart the macro, I get a
> *** Break *** segmentation violation.
> Normally, this happens when I forgot to delete an object,
> however, I could not find any problem with my macro.
>
> When checking "TGNumberEntry.cxx" I realized that
> classes TGNumberEntryField, TGNumberEntryLayout do not
> have a destructor?
> Is this a bug, and could this be the problem? Or do they simply inherit
> the destructor?
>
> Thank you in advance for your help.
>
> Best regards
> Christian
> ----------------------------------
> C.h.r.i.s.t.i.a.n  S.t.r.a.t.o.w.a
> V.i.e.n.n.a,  A.u.s.t.r.i.a
>
> //------------------guiNum.C--------------------
> class XNumEntryGroup {
>
>    RQ_OBJECT()
>
>    private:
>       TGCompositeFrame *fCF;
>       TGLabel           *fLab;
>       TGNumberEntry     *fNum;
>
>       TList  *fTrash;
>
>    public:
>       XNumEntryGroup(TGCompositeFrame *vFrame, UInt_t vWidth, UInt_t
> vHeight,
>          const char *vLabel, Double_t vNum, Int_t vDigits,
>          TGNumberFormat::EStyle vStyle = TGNumberFormat::kNESReal,
>          TGNumberFormat::EAttribute vAttr =
> TGNumberFormat::kNEAAnyNumber,
>          TGNumberFormat::ELimit vLimits = TGNumberFormat::kNELNoLimits,
>          Double_t vMin = 0, Double_t vMax = 1);
>       virtual ~XNumEntryGroup();
>
>       void FSetText(const char *vText)    {fNum->SetText(vText);}
>       void FSetSetDate(Int_t y, Int_t m, Int_t d) {fNum->SetDate(y, m,
> d);}
>       void FGetDate(Int_t& y, Int_t& m, Int_t& d) const
> {fNum->GetDate(y, m, d);}
> };
>
> class MyClass {
>
>    RQ_OBJECT()
>
>    private:
>       TGMainFrame  *fMain;
>       TGCompositeFrame   *fFrameLB;
>       TGButton            *fOkBtn;
>       TGButton            *fCancelBtn;
>       TGGroupFrame       *fF1V1;
>       XNumEntryGroup      *fEGDate;
>
>       TGLayoutHints *fLH1, *fLH2;
>       TList         *fTrash;
>
>    public:
>       MyClass(const TGWindow *vWindow,
>          UInt_t vWidth, UInt_t vHeight, UInt_t vOptions =
> kVerticalFrame);
>       virtual ~MyClass();
>
>    // slots
>       void FCloseWindow();
>       void FClickOK();
>       void FClickCancel();
>
> //      ClassDef(MyClass,0) //NewProjectDlog
> };
>
> //----------------------------------------------------------------------//
>
> XNumEntryGroup::XNumEntryGroup(TGCompositeFrame *vFrame, UInt_t vWidth,
>                 UInt_t vHeight, const char *vLabel, Double_t vNum, Int_t
> vDigits,
>                 TGNumberFormat::EStyle vStyle,
> TGNumberFormat::EAttribute vAttr,
>                 TGNumberFormat::ELimit vLimits, Double_t vMin, Double_t
> vMax)
> {
>    fTrash = new TList;
>    TGLayoutHints *vLH;
>
>    fCF = new TGCompositeFrame(vFrame, vWidth, vHeight,
> kHorizontalFrame);
>    vLH = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX);
>    vFrame->AddFrame(fCF, vLH);
>    fTrash->Add(vLH);
>
>    fLab = new TGLabel(fCF, new TGString(vLabel));
>    vLH = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
>    fCF->AddFrame(fLab, vLH);
>    fTrash->Add(vLH);
>
>    fNum = new
> TGNumberEntry(fCF,vNum,vDigits,-1,vStyle,vAttr,vLimits,vMin,vMax);
>    vLH = new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 2, 5, 5);
>    fCF->AddFrame(fNum, vLH);
>    fNum->Resize(vWidth, fNum->GetDefaultHeight());
>    fTrash->Add(vLH);
> }//Constructor
>
> XNumEntryGroup::~XNumEntryGroup()
> {
>    delete fNum; delete fLab; delete fCF;
>
>    if (fTrash) fTrash->Delete();
>    delete fTrash;
> }//Destructor
>
>
> //----------------------------------------------------------------------//
>
> MyClass::MyClass(const TGWindow *vWindow,
>                  UInt_t vWidth, UInt_t vHeight, UInt_t vOptions)
> {
>    fTrash = new TList;
>
>    TGLayoutHints *vLH;
>
>    fMain   = new TGMainFrame(vWindow, vWidth, vHeight, vOptions);
>    fMain->Connect("CloseWindow()", "MyClass", this, "FCloseWindow()");
>
> // FrameLB for OK, Cancel
>    fFrameLB = new TGHorizontalFrame(fMain, 120, 20, kFixedWidth);
>    fLH1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 2, 2, 5, 1);
>
>    fMain->AddFrame(fFrameLB, fLH1);
>    fTrash->Add(fLH1);
>
>    fOkBtn = new TGTextButton(fFrameLB, "&OK", 1);
>    fOkBtn->Connect("Clicked()", "MyClass", this, "FClickOK()");
>    vLH = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2,
> 15, 2, 2);
>    fFrameLB->AddFrame(fOkBtn, vLH);
>    fTrash->Add(vLH);
>
>    fCancelBtn = new TGTextButton(fFrameLB, "&Cancel", 2);
>    fCancelBtn->Connect("Clicked()", "MyClass", this, "FClickCancel()");
>    vLH = new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 2, 2, 2);
>    fFrameLB->AddFrame(fCancelBtn, vLH);
>    fTrash->Add(vLH);
>
>    fF1V1 = new TGGroupFrame(fMain, "Date Info", kVerticalFrame);
>    vLH = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5,
> 5, 5, 5);
>    fMain->AddFrame(fF1V1, vLH);
>    fTrash->Add(vLH);
>
>    // Date
>    fEGDate = new XNumEntryGroup(fF1V1, 100, 20, "Date(mm/dd/yyyy):",
> 20010101, 10,
>                  TGNumberFormat::kNESMDayYear);
>
> // Main frame settings
>    fMain->MapSubwindows();
>    fMain->Resize(fMain->GetDefaultSize());
>    fMain->SetWMSizeHints(500,300,500,300,0,0);  //no grow
>
>    fMain->SetWindowName("Test");
>    fMain->MapWindow();
> }//Constructor
>
> MyClass::~MyClass()
> {
>    delete fEGDate; delete fF1V1;
>    delete fOkBtn; delete fCancelBtn; delete fFrameLB;
>    delete fMain;
>
>    if (fTrash) fTrash->Delete();
>    delete fTrash;
> }//Destructor
>
> void MyClass::FCloseWindow()
> {
>    delete this;
> }//FCloseWindow
>
> void MyClass::FClickCancel()
> {
>    fMain->SendCloseMessage();
> }//FClickCancel
>
> void MyClass::FClickOK()
> {
>    if (fOkBtn->GetState() != kButtonDisabled) {
>       fMain->SendCloseMessage();
>    }//if
> }//FClickOK
>
>
> //----------------------------------------------------------------------//
>
> void guiNum()
> {
>    new MyClass(gClient->GetRoot(), 400, 220);
> }

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:11 MET