Re: Problem with TSlider

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sat Feb 26 2000 - 11:21:14 MET


Hi Pablo,
When an interpreted class derives from a compiled class, one cannot
exploit the "virtuality" of the virtual declared functions.
If you compile your code, your example will be OK.
I have slighly modified your code below to add the include
declarations, such that the code can be compiled by the new
scipt compiler feature.
With the file slide.C below, you can try a first Root session like
 Root > .x slide.C
and as you have experienced, myHandler::ExecuteEvent is not called
by the compiled code, but it is by the interpreted code.
Using the same file, you can now run with the compiler and the macro
will run correctly.
 Root > .x slide.C++

//-----------------file slide.C
#include "TSlider.h"
#include "TCanvas.h"
class myHandler:public TObject {
   public:
      virtual void ExecuteEvent(int event, int px, int py){
         printf ( "slider moved, event=%d\n",event ) ;
      }
};

void slide () {
   TCanvas *canvas = new TCanvas("Control","STAR L3 Graphic Controls", 0,
0, 500,500 );
   canvas->SetFillColor(42);
   canvas->cd();
   TSlider *phiSlider = new TSlider("xslider","x",0.1,0.02,0.4,0.98);
   myHandler* obj = new myHandler() ;
   obj->ExecuteEvent(1,0,0);
   phiSlider->SetObject ( obj ) ;
}
//-----------------------------

Rene Brun


On Fri, 25 Feb 2000, Pablo Yepes wrote:

> Rene, Fons or whoever reads this,
>     I have been trying to use TSlider. I put together this small macro:
> 
> class myHandler:public TObject {
>    public:
>       virtual void ExecuteEvent(int event, int px, int py){
>          printf ( "slider moved \n" ) ;
>       }
> };
> 
> void sliderExample () {
>    TSlider* phiSlider ;
> 
>    canvas = new TCanvas("Control","STAR L3 Graphic Controls", 0, 0, 500,
> 500 );
>    canvas->SetFillColor(42);
>    canvas->cd();
>    phiSlider = new TSlider("xslider","x",0.1,0.02,0.4,0.98);
>    myHandler* obj = new myHandler() ;
>    obj->ExecuteEvent(1,0,0);
>    phiSlider->SetObject ( obj ) ;
> }
> 
> As far as I understand when I move the slider the "slider moved" message
> 
> should be printed. However it is not.
> I am running on Linux (5.2 or 6.0) and rootversion 2.23/12 (I also tried
> 
> 2.22/10). Am I doing something wrong?
> 
> Another related question: How can I constrained the length of the
> slider.
> I mean by default the slider covers the whole "sliding" area. I cannot
> reduce
> the size of the slide and then slide it. I tried SetMinimum and
> SetMaximum,
> but it did not work.
> 
> Thanks a lot,
> 
> Pablo Yepes
> 
> 
> 



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:20 MET