Page 1 of 1

LoadChartFromStream failed in binary mode

Posted: Fri Sep 09, 2005 10:19 am
by 9336471
Hi,

I try to save two differents charts in a FileStream and Load these two charts with the same FileStream.


Savin g process:

procedure TForm1.SaveStreamBitBtnClick(Sender: TObject);
var
theStream:TFileStream;
begin
OpenDialog1.DefaultExt:='Tee';
OpenDialog1.FilterIndex:=1;
OpenDialog1.Filter:='Files Chart (*.Tee)|*.TEE';
OpenDialog1.Title:='Save TEE file';
If OpenDialog1.Execute then begin
theStream := TFileStream.Create(OpenDialog1.FileName,fmCreate);
SaveChartToStream(Chart1,thestream,true,false);
SaveChartToStream(Chart2,thestream,true,false);
theStream.Free;
end;

and loading process:

procedure TForm1.LoadStreamBitBtnClick(Sender: TObject);
var
theStream:TFileStream;
begin
OpenDialog1.DefaultExt:='Tee';
OpenDialog1.FilterIndex:=1;
OpenDialog1.Filter:='Files Chart (*.Tee)|*.TEE';
OpenDialog1.Title:='Load TEE file';
If OpenDialog1.Execute then begin
theStream := TFileStream.CreateOpenDialog1.FileName,fmOpenRead);
theStream.Seek(0,0);
LoadChartFromStream(TCustomChart(Chart1),theStream);
LoadChartFromStream(TCustomChart(Chart2),theStream);
Chart1.Repaint;
Chart2.Repaint;
theStream.Free;
end;
end;

This code work fine with
SaveChartToStream(Chart1,thestream,true,true);
and failed with
SaveChartToStream(Chart1,thestream,true,false);

More, if I clear chart with Chart.RemoveAllSeries after saving, the program stop after two cycles (save+load) with an access violation.

I have no event attached with charts.

Best regards

Dge

Posted: Mon Sep 12, 2005 8:09 am
by narcis
Hi Dge,

It works fine here using the code below. Could you please test if this works for you? If you use FreeAllSeries(nil), as shown below, really removes the previous series instances.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  For i:=0 to Chart1.SeriesCount - 1 do
  begin
    Chart1[i].FillSampleValues();
    Chart2[i].FillSampleValues();
  end;

end;

procedure TForm1.Button1Click(Sender: TObject);
var
  theStream1, theStream2:TFileStream;
begin
  theStream1 := TFileStream.Create('c:\temp\test1.tee',fmCreate);
  theStream2 := TFileStream.Create('c:\temp\test2.tee',fmCreate);
  SaveChartToStream(Chart1,thestream1,true,true);
  SaveChartToStream(Chart2,thestream2,true,true);
  Chart1.FreeAllSeries(nil);
  Chart2.FreeAllSeries(nil);
  theStream1.Free;
  theStream2.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  theStream1, theStream2:TFileStream;
begin
  theStream1 := TFileStream.Create('c:\temp\test1.tee',fmCreate);
  theStream2 := TFileStream.Create('c:\temp\test2.tee',fmCreate);
  SaveChartToStream(Chart1,thestream1,true,false);
  SaveChartToStream(Chart2,thestream2,true,false);
  Chart1.FreeAllSeries(nil);
  Chart2.FreeAllSeries(nil);
  theStream1.Free;
  theStream2.Free;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  theStream1, theStream2:TFileStream;
begin
  theStream1 := TFileStream.Create('c:\temp\test1.tee',fmOpenRead);
  theStream1.Seek(0,0);
  theStream2 := TFileStream.Create('c:\temp\test2.tee',fmOpenRead);
  theStream2.Seek(0,0);
  LoadChartFromStream(TCustomChart(Chart1),theStream1);
  LoadChartFromStream(TCustomChart(Chart2),theStream2);
  theStream1.Free;
  theStream2.Free;
end;

Posted: Wed Sep 14, 2005 9:11 am
by 9336471
Hi Narcis,

When I save ONE chart in ONE file there is no problem. If I try to save TWO charts in ONE file with streaming process in binary mode, the file is "invalid" but in text mode it is right. It seems that the separation between series data in the first chart and the start of the second chart is wrong. Under debug it seems that the data reading process don't end...

In your answer you say that my code works fine on your computer? (perhaps compiler's options are significant?).

Best regards

Dgé

Posted: Wed Sep 14, 2005 9:21 am
by 9336471
Hi Narcis,

Thank you for your FreeAllseries instead of RemoveAllSeries, it solve the exception problem in a cycle load/save). But the binary problem raise again.

Best regards

Dge

Posted: Wed Sep 14, 2005 10:41 am
by narcis
Hi Dge,
In your answer you say that my code works fine on your computer? (perhaps compiler's options are significant?).
No, I said that the code I posted works fine on my machine.
Thank you for your FreeAllseries instead of RemoveAllSeries, it solve the exception problem in a cycle load/save). But the binary problem raise again.
Do you mean that exporting both charts to the same .tee file? Could you please send us an example we can run "as-is" to reproduce your problem here? You can post your files at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.

Posted: Sat Sep 17, 2005 5:38 pm
by 9336471
Hi Narcis,
I post you a tiny project to fix the problem.
Best reagards

Dge

Posted: Mon Sep 19, 2005 11:48 am
by narcis
Hi Dge,

Thanks for the project. We have been able to reproduce it and this is a bug, only works with text format. I've added it to our defect list to be fixed for future releases.

Posted: Wed Sep 21, 2005 8:43 am
by 9336471
Hi Narcis,

Thank you for yours answer. Waiting for the new version i use the text format.

Best regards

Dge

Posted: Wed Sep 21, 2005 9:51 am
by narcis
Hi Dge,

You're welcome. Please be aware at our Version Info web page to know when this issue (TV52010956) is fixed.