How clone TChart in FMX

  

How do i clone a TChart at runtime? I found this link but it is Delphi and i can’t translate to C++ Builder.

Here is what i tried but i get an error at runtime of Class TChart not found:

TChart *tmp = new TChart(Chart1->Clone(this));
tmp->Parent = this->Panel2;

Also, how can i clone so that i can easily reference the new clones in code – e.g. Chart(2), Chart(3) etc.

EDIT 1: I can clone a button with the following code, but i’m still getting the Class TChart not found when i try with a TChart.

TButton *tmp;
tmp = new TButton(Button1->Clone(this));
tmp->Parent=ToolBar1; // put it on ToolBar1
tmp->Text = “Cloned Button”;

EDIT 2: The following code makes a chart clone and solved the Class TChart not found issue but it does not make a true clone. The image below shows Chart1 and the resulting clone (on Win32). My goal was to make a template chart (Chart1) and then just clone it as i needed new charts…without having to set gobs of properties to make it look like Chart1.

void __fastcall TForm1::Button2Click(TObject *Sender)
{
RegisterClass(__classid(TChart));
TChart* tmp = (TChart*)(Chart1->Clone(Chart1)); // clone Chart1
tmp->Parent = Panel2; // put the new clone on Panel2
tmp->Position->Y = 300;
tmp->BottomAxis->Minimum = -8;
tmp->BottomAxis->Maximum = 8;
tmp->LeftAxis->Minimum = 0;
tmp->LeftAxis->Maximum = 10;
}

Comments are closed.