Re: problem with loaded function

From: Fons Rademakers (rdm)
Date: Sun Sep 28 1997 - 19:46:59 MEST


Hi Pasha,

   the answer is scope. In the function example the TPaveLabel pel
is deleted as soon as the function returns (stack variable goes out
of scope and dtor deletes it from canvas). Use new to create TPaveLabel.

While for the "naive user" macro it works since objects are created in
global scope.

Cheers, Fons.


> 
> 
> 	Hi, new week has not started yet but I've gotten a new confusion:
> 
> 	I've stolen the example ellipse.C from ROOT tutorials, cut it
> 	and put on it jacket of function:
> ----------------------------------------- test.cxx
> display_cot() {
>    gROOT->Reset();
>    c1 = new TCanvas("c1");
>    c1->Range(0,0,1,1);
>    TPaveLabel pel(0.1,0.8,0.9,0.95,"Examples of Ellipses");
>    pel.SetFillColor(42);
>    pel.Draw();
> }
> ----------------------------------------------
> 
> 	Could anybody explain why after
> 
> root [0] .L test.cxx
> root [1] display_cot()
> 
> 	only an empty canvas appears on the screen?  The equivalent (for 
> naive user) macro
> ----------------------------------------- test.C
> {
>    gROOT->Reset();
>    c1 = new TCanvas("c1");
>    c1->Range(0,0,1,1);
>    TPaveLabel pel(0.1,0.8,0.9,0.95,"Examples of Ellipses");
>    pel.SetFillColor(42);
>    pel.Draw();
> }
> ----------------------------------------------
> 	executed via command
> 
> root [2] .x test.C
> 
> 	draws also a label (what naive user would expect)
> 
> 					Thanks a lot, pasha
> 


-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland          Phone: +41 22 7679248
E-Mail: Fons.Rademakers@cern.ch              Fax:   +41 22 7677910



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