Hi,
TeeChartPro 7.04, Delphi 7 Pro
I think there is a bug in
the LoadChartFromStream function. I can't get this code to compile:
procedure TForm1.Button11Click(Sender: TObject);
var memstr: tmemoryStream;
begin
memstr := tmemoryStream.create;
saveChartToStream(chart1, memstr, false, true);
showmessage('Chart saved to memstr');
initChart(Chart1); // clear the chart
memstr.position := 0;
// loadChartFromStream(chart1, memstr);
memstr.free;
end;
When I uncomment that "loadChartFromStream(chart1, memstr);" line, I get
error messages like
[Error] Unit1.pas(273): Types of actual and formal var parameters must be
identical
or a variety of other strange messages. And the error line doesn't line up
to where you'd think the error should be. I think what is happening is that
once you load the chart into a stream, somehow delphi thinks the stream is now a chart!
What I am trying to do is save and load teeCharts to and from Advantage database tables. If you have any examples of using SaveChartToStream and LoadChartFromStream with Advantage Database Tables, I'd sure like to see some.
But, how do you get the LoadChartFromStream to work?
Thanks.
pl
LoadChartFromStream
Solved
Hi,
I figured it out.
1) Create a memo field in the Advantage table. Call it MyChart. The table name is Charts.
2) To save the chart do this:
procedure TForm1.Button6Click(Sender: TObject);
var thestream: tmemoryStream; // SAVE THE CHART TO THE ADV TABLE
begin
try
try
thestream := tmemoryStream.create;
thestream.Position := 0;
SaveChartToStream(tcustomChart(chart1), theStream, false,true);
thestream.Position := 0;
Charts.insert;
ChartsMyChart.LoadFromStream(thestream);
chartsChartname.value := formatDateTime('Chart yyyy-mmm-dd hh:mm:ss ampm', now); // default, change it later.
charts.post;
except
charts.cancel;
showmessage('Could not save to charts');
end;
finally
thestream.free;
end;
end;
3) To load it back in do this: (this loads when I double click on a record in the table's grid)
procedure TForm1.DBGrid1DblClick(Sender: TObject);
var theStream: tmemoryStream;
begin // Load the chart from the Advantage Database table
if chartsMyChart.isnull then
begin
showmessage('The Chart is null');
exit;
end;
try
theStream := tmemoryStream.create;
theStream.position := 0;
chartsMyChart.saveToStream(theStream);
theStream.position := 0;
initChart(Chart1); // this is a routine to clear the chart before loading a saved teechart
loadChartFromStream(tcustomChart(chart1), TheStream);
// re-assign the dependant components...
chartpreviewer1.Chart := Chart1;
teecommander1.ChartEditor.Chart := chart1;
teecommander1.Panel := chart1;
chart1.popupmenu := popupmenu1;
finally
theStream.free;
button1click(self); // plot the chart's points again.
end;
end;
This works ok. The thing that was confusing the compiler was that you have to typecast the chart1 as "tcustomChart(chart1)".
pl
I figured it out.
1) Create a memo field in the Advantage table. Call it MyChart. The table name is Charts.
2) To save the chart do this:
procedure TForm1.Button6Click(Sender: TObject);
var thestream: tmemoryStream; // SAVE THE CHART TO THE ADV TABLE
begin
try
try
thestream := tmemoryStream.create;
thestream.Position := 0;
SaveChartToStream(tcustomChart(chart1), theStream, false,true);
thestream.Position := 0;
Charts.insert;
ChartsMyChart.LoadFromStream(thestream);
chartsChartname.value := formatDateTime('Chart yyyy-mmm-dd hh:mm:ss ampm', now); // default, change it later.
charts.post;
except
charts.cancel;
showmessage('Could not save to charts');
end;
finally
thestream.free;
end;
end;
3) To load it back in do this: (this loads when I double click on a record in the table's grid)
procedure TForm1.DBGrid1DblClick(Sender: TObject);
var theStream: tmemoryStream;
begin // Load the chart from the Advantage Database table
if chartsMyChart.isnull then
begin
showmessage('The Chart is null');
exit;
end;
try
theStream := tmemoryStream.create;
theStream.position := 0;
chartsMyChart.saveToStream(theStream);
theStream.position := 0;
initChart(Chart1); // this is a routine to clear the chart before loading a saved teechart
loadChartFromStream(tcustomChart(chart1), TheStream);
// re-assign the dependant components...
chartpreviewer1.Chart := Chart1;
teecommander1.ChartEditor.Chart := chart1;
teecommander1.Panel := chart1;
chart1.popupmenu := popupmenu1;
finally
theStream.free;
button1click(self); // plot the chart's points again.
end;
end;
This works ok. The thing that was confusing the compiler was that you have to typecast the chart1 as "tcustomChart(chart1)".
pl