【问题标题】:c++ builder: dynamically remove all TPanel's from TFramedVertScrollBoxc ++ builder:从TFramedVertScrollBox中动态删除所有TPanel
【发布时间】:2016-05-09 17:43:38
【问题描述】:

在我的 C++ Builder 项目中,我有一个动态获取 TPanel 的 TFramedVertScrollBox (pnl_art_box)。我想在添加“新”之前清除所有现有的 TPanel。

for(int i = 0; i < this->pnl_art_box->ComponentCount; i++)
{
    // this here is where i dont find any solution ...
    this->pnl_art_box->Components[i]->DestroyComponents(); 
}
for(int i = 0; i < i_article_amount;i++)
{
    this->articlelistpanels[i] = new TPanel(this->pnl_art_box);
    this->articlelistlabels[i] = new TLabel(this);

    this->articlelistlabels[i]->Text = this->articlelist[i].get_name();
    this->articlelistpanels[i]->Align = Fmx::Types::TAlignLayout::MostTop;

    this->articlelistpanels[i]->AddObject(this->articlelistlabels[i]);
    this->pnl_art_box->AddObject(this->articlelistpanels[i]);
}

在 Google,我只找到了非常少的帮助,而且没有一个是用 C++ 编写的;

如果我做错了,如果有人能告诉我,那就太好了。

此致蒂莫·特雷切尔

【问题讨论】:

  • 您是否尝试过删除 articlelistpanels/labels 中的所有元素并清除它们(如果是向量或列表或...)?可能,您需要先调用 RemoveObject。
  • 这也没有带来任何影响,因为旧组件仍在this-&gt;pnl_art_box中列出
  • 您是否尝试过简单地调用this-&gt;pnl_art_box-&gt;DestroyComponents();this-&gt;pnl_art_box-&gt;DeleteChildren();(不确定更喜欢哪一个 - 倾向于后者)而不是 for 循环?如果您反复这样做,请注意您的两个列表的内容很可能会变得无效!
  • 是的,我做到了,他们都没有想要的效果......我终于找到了解决方案,它是this-&gt;pnl_art_box-&gt;Components[i]-&gt;DisposeOf();

标签: c++builder destroy tpanel


【解决方案1】:

我终于自己找到了。 正确的命令是:

for(int i = 1; i < this->pnl_art_box->ComponentCount; i++)
{
    this->pnl_art_box->Components[i]->DisposeOf();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多