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.
Series1.AddXY after LoadChartFromFile
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".
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".
Or alternatively, manually redeclare Series1 as:
Practically speaking using Chart1.Series[0] is safer and better solution than declaring variables after chart is loaded.
Code: Select all
Series1 := Chart1.Series[0] as TLineSeries;
// if Series1 is declared as line series
Marjan Slatinek,
http://www.steema.com
http://www.steema.com