【发布时间】: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->pnl_art_box中列出 -
您是否尝试过简单地调用
this->pnl_art_box->DestroyComponents();或this->pnl_art_box->DeleteChildren();(不确定更喜欢哪一个 - 倾向于后者)而不是 for 循环?如果您反复这样做,请注意您的两个列表的内容很可能会变得无效! -
是的,我做到了,他们都没有想要的效果......我终于找到了解决方案,它是
this->pnl_art_box->Components[i]->DisposeOf();
标签: c++builder destroy tpanel