简体   繁体   English

如何在FMX中克隆TChart

[英]How clone TChart in FMX

How do i clone a TChart at runtime? 如何在运行时克隆TChart? I found this link but it is Delphi and i can't translate to C++ Builder. 我找到了此链接,但它是Delphi,我无法转换为C ++ Builder。

Here is what i tried but i get an error at runtime of Class TChart not found : 这是我尝试过的方法,但在运行时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 - eg Chart(2) , Chart(3) etc. 另外,我该如何克隆,以便可以轻松地在代码中引用新的克隆-例如Chart(2)Chart(3)等。

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. 编辑1 :我可以使用以下代码克隆按钮,但是当我尝试使用TChart时,我仍然Class TChart not found 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. 编辑2 :以下代码制作了一个图表克隆,并解决了Class TChart not found问题,但它没有真正的克隆。 The image below shows Chart1 and the resulting clone (on Win32). 下图显示了Chart1和生成的克隆(在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. 我的目标是制作一个模板图表(Chart1),然后在需要新图表时将其克隆...而不必设置属性块以使其看起来像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;
}

Chart1及其克隆

A TChart component can be cloned with the function CloneChart . TChart组分可与所述功能被克隆CloneChart

TChart* tmp = new TChart(this);
CloneChart(tmp, Chart1, this, false);
tmp->Parent = this->Panel2;

You could save pointers to the created TChart objects in a vector. 您可以将指向创建的TChart对象的指针保存在向量中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM