Series1.AddXY after LoadChartFromFile

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
UE
Newbie
Newbie
Posts: 4
Joined: Wed Aug 25, 2004 4:00 am

Series1.AddXY after LoadChartFromFile

Post by UE » Thu Dec 30, 2004 12:19 pm

I'm using a TChart with one TLineSeries on a Form (Created in Delphi IDE Designer). I will load a Chart from a file - then I will add new points to my Series.

I tried following code:

Series1.AddXY(1,1);
SaveChartToFile(Chart1, 'c:\temp\chart.tee', true,false);
LoadChartFromFile(TCustomChart(Chart1), 'c:\temp\chart.tee');

Series1.AddXY(2,2); -> Access violation cause Series is nil after loading!!!

How can I get the new pointer of the Series1 to add new points after loading chart from a file?

Tanks.

ungos
Newbie
Newbie
Posts: 12
Joined: Mon Oct 04, 2004 4:00 am
Location: Czech Republic
Contact:

Post by ungos » Thu Dec 30, 2004 1:41 pm

After loading chart, original series objects are lost a new will be created (if loaded chart consists any). You must use Chart.Series property to access new series:

Chart1.Series[0].AddXY(2,2)

Also, by my experience, is good practice to initialize chart object before LoadChartFromStream. See my reply in previous article "Cut and paste of TChart and its content".

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Thu Dec 30, 2004 2:40 pm

Or alternatively, manually redeclare Series1 as:

Code: Select all

Series1 := Chart1.Series[0] as TLineSeries;
// if Series1 is declared as line series
Practically speaking using Chart1.Series[0] is safer and better solution than declaring variables after chart is loaded.
Marjan Slatinek,
http://www.steema.com

Post Reply