Page 1 of 1

TChart can't be cloned with Clone() Function?

Posted: Thu Nov 14, 2013 11:57 am
by 16566869
Hello,
TChart can't be cloned with Clone() Function?
The exception shows that "The TChart class can't be found"..

Re: TChart can't be cloned with Clone() Function?

Posted: Thu Nov 14, 2013 12:01 pm
by narcis
Hi elmec,

Are you adding FMXTee.Chart unit to your project's uses section? Code below works fine for me.

Code: Select all

uses
  FMXTee.Chart;

procedure TForm2.FormCreate(Sender: TObject);
var Chart1,Chart2: TChart;
begin
  Chart1:=TChart.Create(Self);
  Chart2:=(Chart1.Clone(Self) as TChart);
end;
If the problem persists please attach a simple example project we can run "as-is" to reproduce the problem here.

Thanks in advance.

Re: TChart can't be cloned with Clone() Function?

Posted: Thu Nov 14, 2013 12:07 pm
by 16566869
The example project.

Re: TChart can't be cloned with Clone() Function?

Posted: Thu Nov 14, 2013 2:12 pm
by narcis
Hi elmec,

C++ Builder needs to call RegisterClass befor calling Clone:

Code: Select all

void __fastcall TForm12::btnCopyClick(TObject *Sender)
{
	RegisterClass(__classid(TChart));

	TChart* chartcopyed =  (TChart*)(Chart1->Clone(Chart1));
	chartcopyed->Parent = this;

	chartcopyed->Align = TAlignLayout::alClient;
}
If there were series on tha chart you should also use:

Code: Select all

#pragma link "FMXTee.Series"
RegisterTeeStandardSeries();

Re: TChart can't be cloned with Clone() Function?

Posted: Fri Nov 15, 2013 2:22 am
by 16566869
After the follow code added,

Code: Select all

RegisterClass(__classid(TChart));
RegisterTeeStandardSeries();
The TChart gets to OK, but the series still failed to be cloned.

Re: TChart can't be cloned with Clone() Function?

Posted: Fri Nov 15, 2013 9:05 am
by narcis
Hi elmec,

Actually series are being cloned. What is not cloned is their data. You should manually do that using AssignValues:

Code: Select all

void __fastcall TForm12::btnCopyClick(TObject *Sender)
{
	 TChart* chartcopyed =  (TChart*)(Chart1->Clone(this));
	 chartcopyed->Parent = this;

	 chartcopyed->Align = TAlignLayout::alClient;

	 for (int i = 0; i < Chart1->SeriesCount(); i++) {
		 chartcopyed->Series[i]->AssignValues(Chart1->Series[i]);

		 //Code to clone series
		//CloneChartSeries(Chart1->Series)->ParentChart=chartcopyed;
	 }
}

Re: TChart can't be cloned with Clone() Function?

Posted: Fri Nov 15, 2013 9:34 am
by 16566869
Hello Narcís ,
It works!
Thank you so much!

BTW, is it a bug or just Tchart's behavior?

Re: TChart can't be cloned with Clone() Function?

Posted: Fri Nov 15, 2013 9:58 am
by narcis
Hi elmec,
elmec wrote:Hello Narcís ,
It works!
Thank you so much!
You're welcome.
elmec wrote:Hello Narcís ,
BTW, is it a bug or just Tchart's behavior?
This is as designed.