Re: calling functions from a TControlBar button.

Rene Brun (Rene.Brun@cern.ch)
Fri, 16 Oct 1998 10:07:21 +0200


Frederic FAURE wrote:
>
> Hello,
> >From a TControlBar button, i don't succeed to call class member functions i
> wrote,
> except for already defined root function.
> (I use ROOT with XLC compilation on AIX, IBM.)
>
> This is an example:
>
> //-----------------------------------
> class Fenetre: public TCanvas
> {
> public:
> Fenetre::Fenetre(Text_t* name, Text_t* title, Int_t ww, Int_t wh) :
> TCanvas(name,title,ww,wh) // constructeur
> {}
>
> void Fenetre::Affiche(int a)
> {cout<<"a="<<a<<endl; }
>
> };
> //-------------------------
> void fonction(int a)
> { cout<<a<<endl;}
> //------------------------------------
> int main(int argc, char **argv)
> {
> Fenetre *c = new Fenetre("c", "Essai de fenetre", 400,400);
>
> TControlBar bar("vertical");
> bar.AddButton("buyton1","fonction(2)","essai");
> bar.AddButton("button2","c->Affiche(3)","essai");
> bar.Show();
> gROOT->SaveContext();
> }
> //----------------------------
>
> the error with button 1 is:
> Error: No symbol fonction(2) in current scope FILE:/tmp/caaZ0tcyc LINE:1
> *** Interpreter error recovered ***
>
> the error with button 2 is:
> Error: Can't call TCanvas::Affiche() in current scope FILE:/tmp/baaXPtcyb
> LINE:1
> *** Interpreter error recovered ***
>
> I anderstand that the problem is that the global variable: fonction(int)
> and the class member Fenetre::Affiche() must be known from the system,
> but how to do that?
>

Frederic,
INTERPRETED CLASSES CANNOT DERIVE FROM COMPILED CLASSES.
Even, in the assumption that this feature will be implemented in the
future in CINT, your macro will not work.
The actions specified for a TControlBar must be valid commands
given to the interpreter.
When you execute the statement:
bar.AddButton("button2","c->Affiche(3)","essai");
Root creates a new button with the allocated action "c->Affiche(3)"
At this point, no problems. But when you will press the corresponding
button, the variable c is not in the scope any more.
In the actions to a button, you can only give commands that you
could also type at the command line instead of pressing the button.
In your case the first button is OK, because void fonction(int a)
is a function know to the interpreter.

Rene Brun