Page 1 of 1

Erreur when loading chart file

Posted: Mon Nov 23, 2009 10:10 am
by 10050873
Hello,

Here is the code to save charts to file

Code: Select all

      SaveChartToFile(ChrtProdSynthese,frmMain.PathAppli+'Config\GraphSynthese0.tee',FALSE);
      SaveChartToFile(ChrtDispoSynthese,frmMain.PathAppli+'Config\GraphSynthese1.tee',FALSE);
      SaveChartToFile(ChrtVitSynthese,frmMain.PathAppli+'Config\GraphSynthese2.tee',FALSE);
      SaveChartToFile(ChrtRealTheoSynthese,frmMain.PathAppli+'Config\GraphSynthese3.tee',FALSE)
Here is the code to load the charts

Code: Select all

  SetLength(frmMain.ChrtModel,4);
  //si un fichier de config des courbes existe on le charge
  for i := 0 to High(frmMain.ChrtModel) do
  begin
    if FileExists(frmMain.PathAppli+'Config\GraphSynthese'+IntToStr(i)+'.tee') then
    begin
      frmMain.ChrtModel[i]:=TChart.Create(self);
      LoadChartfromFile(frmMain.ChrtModel[i],frmMain.PathAppli+'Config\GraphSynthese'+IntToStr(i)+'.tee');
    end;
  end;
When the loadchartfromfile is called with i=1 i have the message "components named _1 already exists"

I don't understand why ?

Thanks for help

Regards

Re: Erreur when loading chart file

Posted: Mon Nov 23, 2009 12:10 pm
by 10050873
I have done some other tests.

The error occur only when i use the TADVStringGrid (version 5) from TMSSoftware.

You can do a simple exampe. If you call loadchartfromfile with a TadvSTringgrid on the form it crashes

Regards

Re: Erreur when loading chart file

Posted: Mon Nov 23, 2009 12:21 pm
by yeray
Hi Calou,

I've been doing some tests to try to reproduce the error but couldn't. Here is the complete demo example I've been testing with:

Code: Select all

uses Chart, Series, TeeStore, TeeEditPro;

var Charts: array[0..3] of TCustomChart;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:=0 to length(Charts)-1 do
  begin
    Charts[i]:=TChart.Create(self);
    Charts[i].Parent:=Form1;

    Charts[i].Left:=Charts[i].Width*(i mod 2);
    Charts[i].Top:=Charts[i].Height*(i div 2);

    case i of
      0: Charts[i].AddSeries(TPointSeries.Create(self));
      1: Charts[i].AddSeries(TBarSeries.Create(self));
      2: Charts[i].AddSeries(TLineSeries.Create(self));
      else
       Charts[i].AddSeries(TFastLineSeries.Create(self));
    end;

     Charts[i][0].FillSampleValues();
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
  for i:=0 to length(Charts)-1 do
    SaveChartToFile(Charts[i],'C:\tmp\Chart' + inttostr(i) + '.tee',true,true);
end;

procedure TForm1.Button2Click(Sender: TObject);
var i: Integer;
    FileName: string;
begin
  for i := 0 to length(Charts)-1 do
  begin
    FileName:='C:\tmp\Chart' + inttostr(i) + '.tee';
    if FileExists(FileName) then
    begin
      Charts[i]:=TChart.Create(self);
      Charts[i].Parent:=Form1;

      Charts[i].Left:=Charts[i].Width*(i mod 2);
      Charts[i].Top:=Charts[i].Height*(i div 2);

      LoadChartfromFile(Charts[i],FileName);
    end;
  end;
end;
As you say, this could be due to another component compatibility problem. Please check if you can obtain a simple string from the TADVStringGrid, if there are related problems with that component and if you can reproduce the error without using TeeChart or without TadvSTringgrid.

Re: Erreur when loading chart file

Posted: Mon Nov 23, 2009 12:58 pm
by 10050873
I have tested your example

Without the ADVSTringGrid no error. With the ADVStringGrid there is the error (name _1)
After called the LoadChartFromfile Function, without AdvStringGrid the name of charts (Charts.name) is '' and with the AdvStringGrid it is '_1'
It is the same behavior if charts is not an array

Thanks for help

Re: Erreur when loading chart file

Posted: Mon Nov 23, 2009 1:39 pm
by 10050873
I am not able to reproduce this behavior with only AdtStringGrid.
Let me know if you want that i do others tests

Regards

Re: Erreur when loading chart file

Posted: Tue Nov 24, 2009 8:45 am
by 10050873
Hello,

Have you found something? Sorry to insist but my developpement is stopped now :oops:

Thanks for feedback

Regards

Re: Erreur when loading chart file

Posted: Tue Nov 24, 2009 3:56 pm
by yeray
Hi Calou,

I've been testing this and yes, it seems that having a TAdvStringGrid in the same form than a Chart, makes the following code to crash the second time the button is pressed (the second time the chart is imported).

But I've also found that freeing the chart variable seems to solve the problem:

Code: Select all

uses Chart, Series, TeeStore, TeeEditPro;

var Chart1: TCustomChart;
    FileName: string;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1:=TChart.Create(self);
  Chart1.Parent:=Self;
  Chart1.AddSeries(TPointSeries.Create(self));
  Chart1[0].FillSampleValues();

  FileName:='C:\tmp\Chart1.tee';

  SaveChartToFile(Chart1,FileName,true,true);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  //Chart1.Free;  //This seems to solve the problem when a TAdvStringGrid is in the form

  if FileExists(FileName) then
  begin
    Chart1:=TChart.Create(self);
    Chart1.Parent:=Self;
    LoadChartfromFile(Chart1,FileName);
  end;
end;

Re: Erreur when loading chart file

Posted: Tue Nov 24, 2009 4:24 pm
by 10050873
hello,

I have modified your example like this :

Code: Select all

procedure TForm1.Button2Click(Sender: TObject);
var i: Integer;
    FileName: string;
begin
  for i := 0 to length(Charts)-1 do
  begin
    FileName:='C:\tmp\Chart' + inttostr(i) + '.tee';
    if FileExists(FileName) then
    begin
      Charts[i].free;//for test with advstringgrid

      Charts[i]:=TChart.Create(self);
      Charts[i].Parent:=Form1;

      Charts[i].Left:=Charts[i].Width*(i mod 2);
      Charts[i].Top:=Charts[i].Height*(i div 2);

      LoadChartfromFile(Charts[i],FileName);
    end;
  end;
end;
But i always have the error

Thanks

Re: Erreur when loading chart file

Posted: Wed Nov 25, 2009 3:47 pm
by 10050873
Hello,

I am very sorry to insist :oops: but have you find something to correct the problem?

Thank you very much for the feedback

Regards

Re: Erreur when loading chart file

Posted: Wed Nov 25, 2009 4:04 pm
by yeray
Hi Calou,

We will study the problem and to be back to you asap. If you want, you can get priority support.

Re: Erreur when loading chart file

Posted: Wed Nov 25, 2009 4:07 pm
by 10050873
Many thanks Yeray

Re: Erreur when loading chart file

Posted: Wed Nov 25, 2009 4:37 pm
by yeray
Hi Calou,

Adding the following line in the for loop, just before the LoadChartFromFile call, seems to solve the problem. Could you please verify it?

Code: Select all

Charts[i].Name:='Chart' + inttostr(i);

Re: Erreur when loading chart file

Posted: Wed Nov 25, 2009 5:10 pm
by 10050873
I will do more tests tomorrow but it seems to be good

Many thanks