Page 1 of 1

TChartBook->AddChart() returns NULL

Posted: Mon Feb 01, 2010 2:51 pm
by 10548242
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?

Re: TChartBook->AddChart() returns NULL

Posted: Tue Feb 02, 2010 12:33 am
by 10548242
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

Re: TChartBook->AddChart() returns NULL

Posted: Tue Feb 02, 2010 4:32 pm
by yeray
Hi reef,

Thanks for the feedback. I hope it will help another user.