Issue with reloading a chart saved to a custom DFM file

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
bfrost
Newbie
Newbie
Posts: 7
Joined: Wed Mar 16, 2011 12:00 am

Issue with reloading a chart saved to a custom DFM file

Post by bfrost » Fri Feb 08, 2013 10:01 pm

files.zip
Demo project
(2.27 KiB) Downloaded 362 times
Hi, I wish to use a TChart within a wrapper component together with some other stuff and for the TChart properties and my stuff to get streamed to a DFM format file. I want to use the standard TStream.WriteComponent and TStream.ReadComponent. THere is only one series and I'm creating that at runtime and populating with data too. To prove that this works, on a button event I create an instance of my wrapper and show it on a form. It displays fine. Using another button, my wrapper is streamed to a DFM format file and inspecting the contents, I can see my wrapper properties and those of the TChart (see 'test.txt' in the zip). When I use the load routine my wrapper is redrawn and the TChart color changes (if I've saved it with a different color) but no series points appear (as if there is no series or series data) yet inspecting the chart it has the same single line series with the original 100 points of data. Clearly some property of the TChart is causing it not to show the series data. Can anyone help? My simple test project is attatched. To see the effect:

1. Run the program - a chart will be seen on the form.
2. click 'Change Color' and see the chart background change.
3. Click 'save' and a file 'test.txt' is written to your desktop - open it and you will see the saved properties.
4. Click 'load' and see the chart reloaded showing only axes. Where is the series? It is there in code but not visible.

Any help appreciated. Thanks, Brian.


As a test for a wrapper I have created my own panel component at runtime which contains a TChart. Again, at runtime I show this panel on a form

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Issue with reloading a chart saved to a custom DFM file

Post by Yeray » Tue Feb 12, 2013 9:38 am

Hi Brian,

You aren't exporting the series data. Set the ForceSaveData property to true to do so:

Code: Select all

type
  //...
  TSeriesAccess=class(TChartSeries);
  //...
constructor TMyChart.Create(AOwner: TComponent);
begin
  //...
  TSeriesAccess(FChart.Series[0]).ForceSaveData:=True;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

bfrost
Newbie
Newbie
Posts: 7
Joined: Wed Mar 16, 2011 12:00 am

Re: Issue with reloading a chart saved to a custom DFM file

Post by bfrost » Wed Feb 13, 2013 10:15 am

Hi Yerey,
I dont want or need to export the series data - if you look at the code you will see that I am using 'FillRandom' to generate the series data - in my real app I make the data myself.
The problem is that the series gets created and IT HAS THE DATA (Chart1.Series[0].Count is 100) but it does not get displayed.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Issue with reloading a chart saved to a custom DFM file

Post by Yeray » Wed Feb 13, 2013 4:18 pm

Hi Brian,

We've been looking at this, modifying your loading routine in different ways, etc.
I'm not sure about what is wrong here but maybe our test give you some kind of clue to find it.

First, I've added a new button to open the editor:

Code: Select all

uses VCLTee.TeeEdit;

procedure TForm8.BEditorClick(Sender: TObject);
begin
  with TChartEditor.Create(Self) do
  begin
    Chart:=FMyChart.Chart;
    Execute;
  end;
end;
If you click Save&Load and then you open the editor, you can see how the global variable FMyChart seems to be still referencing the old chart; the chart with a series and data.
So this smells like FMyChart variable has been, at least partially broken.
Furthermore, if you reassign the FMyChart Parent and you set its Chart.Align to alNone after loading the stream, you'll observe how the original FMyChart seems to be restored:

Code: Select all

  LoadComponentFromFile( TComponent(FMyChart) );
  FMyChart.Chart.Parent:=Self;
  FMyChart.Chart.Align:=alNone;
Since you are a SourceCode customer I'd suggest you to take a look at how SaveChartToFile and LoadChartFromFile (TeeStore.pas) methods are implemented.
I'd also suggest you to see how in the "Tutorial 12 - Exporting and Importing Charts", when we import a chart from a file, we Free the original chart, we load the stream to a tmpChart and we assign it to the original freed chart:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var tmpChart : TCustomChart;
begin
  Chart1.Free;   // Assuming Chart1 is already on the Form
  tmpChart:=TChart.Create(Self);

  With OpenDialog1 do
  begin
    Filter:= 'Teefiles|*.tee';
    if Execute then 
       LoadChartfromFile(tmpChart,OpenDialog1.FileName);
  end;

  Chart1 := tmpChart as TChart;

  With Chart1 do
  begin
    Parent:=Self;
  end;
end;
Maybe something similar has to be done in your custom importation.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

bfrost
Newbie
Newbie
Posts: 7
Joined: Wed Mar 16, 2011 12:00 am

Re: Issue with reloading a chart saved to a custom DFM file

Post by bfrost » Wed Feb 13, 2013 5:30 pm

Hi Yeray, Thanks for your suggestions. I will investigate.

Post Reply