Re: Standalone Code, scope, TControlBar

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Aug 02 1999 - 18:08:08 MEST


Hi Jon,
When you use the class TRint, you have to add -lRint in your list of
libs.

Your program cannot work, because CINT has no way to know that you have
created a local variable x in the main program.
To understand TControlBar, I suggest you start by playing with the
following
small macro. As already reported several times, the action specified
in a TControlBar can only be something that you can also execute
at the command line.

//macro demo.C
int x=10;
void test()
{
   TControlBar *bar = new TControlBar("vertical");
   bar->AddButton("Increment x","x++;","increment variable x by 1");
   bar->AddButton("Show x","printf(\"x=%d\\n\",x);","Print current value
of x");
   bar->Show();
}

Now using the standard root, do;
 Root > .L demo.C
 Root > test(); // this will show you the control bar.
You can now click on the Increment or/and Show buttons.

Rene Brun

Jon Gans wrote:
> 
> After fixing all GUI stuff, I find the variables do not stay in scope in
> the controlbar. for example, with the following code, I get this error
> when the Test button is pressed:
>         Error: No symbol x in current scope  FILE:/tmp/27101aaa_cint LINE:1
> 
> here is the code:
> 
> #ifndef __CINT__
> #include <iostream.h>
> #include "TROOT.h"
> #include "TRint.h"
> #include "TControlBar.h"
> #include "TApplication.h"
> #endif
> 
> extern void InitGui();
> VoidFuncPtr_t initfuncs[] = { InitGui, 0 };
> 
> TROOT root("richView", "Rich Viewer",initfuncs);
> 
> int main(int argc, char **argv)
> {
> 
>   TApplication * theApp = new TApplication("RichEvent", &argc, argv);
>   // TRint * theApp = new TRint("RichEvent",&argc,argv,0,0);
> 
>   int x = 10;
> 
>  TControlBar bar("vertical");
>  bar.AddButton("Test", "x++;", "test");
>  bar.Show();
> 
>   theApp->Run();
>   return 0;
> }
> 
> moreover, if i switch to TRint instead of TApplication i get:
> undefined reference to `TRint::TRint(char *, int *, char **, void *, int)'
> 
> I know TRint.h is included because if i comment out the include line a get
> many more errors.
> 
> I am on Linux 5.2 running Root 2.22/10
> 
>  thanks alot
>  jon
> 
> ______________________________________________________________________________
> 
> Jonathan Gans                                      Home: 516 344 1265
> Brookhaven National Lab                            Work: 516 344 7405
> Building 902b, Room 11                   Fax/Voice Mail: 516 213 4967 (LI)
> Upton, NY 11973                            (Via Email)   718 247 2926 (NYC)
>                 http://star.physics.yale.edu/users/gans



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