Re: delete ToolBar

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Jan 09 1998 - 12:27:00 MET


Yves Schutz wrote:

> I have an error while trying to delete a TControllbar. The TControlbar is declared in a macro called test.cc which is execute in
> my rootlogon.cc.
>
> Here is my rootlogon.cc
>
> void rootlogon()
> {
>  #include <iostream.h>
>
> // Create the canvas
>  TCanvas * MyCanevas = new TCanvas("MyCanevas", "WA98 Pb+Pb 95 analysis");
> // Produce the main control bar
>  gROOT->Macro("test.cc");
> }
>
> and here comes the macro test.cc :
>
>  TControlBar * main_bar = new TControlBar("horizontal","main","main analysis menu");
>
>  main_bar->SetNumberOfColumns(1);
>
>  main_bar->AddButton("Close","{MyCanevas->Close(); delete main_bar;}","Close this toolbar");
>
>  main_bar->Show();
> }
>
> by selecting the button  Close, I get the following error :
>
> root [0] Error: No symbol main_bar in current scope  FILE:/tmp/12940aaa LINE:1
> Error: main_bar==NULL cannot delete FILE:/tmp/12940aaa LINE:1
> *** Interpreter error recovered ***
>
> Curiously the problem can be solved by changing the declaration in  test.cc by :
>
>  main_bar = new TControlBar("horizontal","main","main analysis menu");

Your macro test.cc is executed within the scope of rootlogon.
When rootlogon exits, all  variables created in its scope
are deleted.
Simply execute rootlogon in the global scope==>delete the statement
void rootlogon()  in rootlogon.cc

Rene Brun



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