Page 1 of 1

Series1.AddXY after LoadChartFromFile

Posted: Thu Dec 30, 2004 12:19 pm
by 9233743
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.

Posted: Thu Dec 30, 2004 1:41 pm
by 9234468
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".

Posted: Thu Dec 30, 2004 2:40 pm
by Marjan
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.