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

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

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

Post by elmec » Thu Nov 14, 2013 11:57 am

Hello,
TChart can't be cloned with Clone() Function?
The exception shows that "The TChart class can't be found"..

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

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

Post by Narcís » Thu Nov 14, 2013 12:01 pm

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

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

Post by elmec » Thu Nov 14, 2013 12:07 pm

The example project.
Attachments
CopyChart.zip
(74.6 KiB) Downloaded 517 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

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

Post by Narcís » Thu Nov 14, 2013 2:12 pm

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();
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

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

Post by elmec » Fri Nov 15, 2013 2:22 am

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.
Attachments
CopyChart.zip
(81.7 KiB) Downloaded 567 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

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

Post by Narcís » Fri Nov 15, 2013 9:05 am

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;
	 }
}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

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

Post by elmec » Fri Nov 15, 2013 9:34 am

Hello Narcís ,
It works!
Thank you so much!

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

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

Post by Narcís » Fri Nov 15, 2013 9:58 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply