【发布时间】:2019-06-25 02:06:41
【问题描述】:
如何在运行时克隆 TChart?我找到了this link,但它是 Delphi,我无法转换为 C++ Builder。
这是我尝试过的,但在运行时出现Class TChart not found 错误:
TChart *tmp = new TChart(Chart1->Clone(this));
tmp->Parent = this->Panel2;
另外,我如何克隆,以便我可以轻松地在代码中引用新的克隆 - 例如Chart(2)、Chart(3)等
编辑 1:我可以使用以下代码克隆一个按钮,但是当我尝试使用 TChart 时,我仍然得到 Class TChart not found。
TButton *tmp;
tmp = new TButton(Button1->Clone(this));
tmp->Parent=ToolBar1; // put it on ToolBar1
tmp->Text = "Cloned Button";
编辑 2:以下代码克隆了一个图表并解决了 Class TChart not found 问题,但它没有进行真正的克隆。下图显示了 Chart1 和生成的克隆(在 Win32 上)。我的目标是制作一个模板图表(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;
}
【问题讨论】:
-
你可以使用函数
CloneChart -
嗨,Kerem - 我一直在尝试使用
CloneChart,但似乎存在一些问题(我正在查看 Steema 用户论坛)。我无法让它成为一个真正的克隆。我将在我的原始帖子中添加“EDIT 2”,以便您了解我的意思。
标签: firemonkey c++builder teechart