TChartBook->AddChart() returns NULL

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
reef
Newbie
Newbie
Posts: 2
Joined: Wed Feb 06, 2008 12:00 am

TChartBook->AddChart() returns NULL

Post by reef » Mon Feb 01, 2010 2:51 pm

I have a form in which I've placed a TChartBook component Data_Man_ChartBook. However, when I try to add a chart to this component using the following:

TCustomChart* tmp;

//Add a new chart to the Data_Man_ChartBook

Data_Man_ChartBook->AddChart();
Data_Man_ChartBook->ActivePageIndex = Data_Man_ChartBook->PageCount - 1;
tmp = Data_Man_ChartBook->ActiveChart();

tmp returns NULL. Any attempt to reference the chart, for example:

Data_Man_ChartBook->ActiveChart()->View3D = false;

gives an error.

What am I doing wrong?

reef
Newbie
Newbie
Posts: 2
Joined: Wed Feb 06, 2008 12:00 am

Re: TChartBook->AddChart() returns NULL

Post by reef » Tue Feb 02, 2010 12:33 am

Found the answer. I used the above code in the initialization of the class:
__fastcall TFrame1::TFrame1(TComponent* Owner)
:TFrame(Owner)
{
//Try to add a chart here
}

That doesn't work. So, I did the following:

__fastcall TFrame1::TFrame1(TComponent* Owner)
:TFrame(Owner)
{
}

void TFrame1::InitFrame ()
{
//Add the chart to the chartbook.
}

.....
__fastcall TMainForm::TMainForm(TComponent *Owner)
: TForm(Owner)
{
Frame11->InitFrame();
...
}

Now it works. I guess the ChartBook isn't created until the entire frame is created. So, DON'T try to add a chart to a chart book inside the initialization of the frame.

Reef

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TChartBook->AddChart() returns NULL

Post by Yeray » Tue Feb 02, 2010 4:32 pm

Hi reef,

Thanks for the feedback. I hope it will help another user.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply