【问题标题】:How clone TChart in FMX如何在 FMX 中克隆 TChart
【发布时间】: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


【解决方案1】:

TChart 组件可以通过函数CloneChart 进行克隆。

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

您可以将指向创建的TChart 对象的指针保存在向量中。

【讨论】:

  • Kerem - 除了新图表不像 Chart1 那样锚定在右侧之外,此方法有效。我也不知道如何在 C++ 中锚定它。 This link 展示了如何在 Delphi 中执行此操作,但不知道如何在 C++ 中执行此操作。我只想把它固定在左右两边。
  • 经过大量搜索后通过tmp->Align = TAlignLayout::Horizontal 得到它。 This link 帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-17
  • 2016-03-31
  • 2021-11-11
  • 2012-09-30
  • 2012-08-08
相关资源
最近更新 更多