1

In my C++ Builder Project i have a TFramedVertScrollBox (pnl_art_box) which dynamically gets TPanel's. I want to clear out all existing TPanel's before adding the "new" ones.

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]);
}

At Google i only found very less help and none of them is in C++;

Would be nice, if someone could tell me, when i do wrong.

Sincerely Timo Treichel

sergiol
  • 4,122
  • 4
  • 47
  • 81
Timo Treichel
  • 358
  • 3
  • 14
  • Have you tried just do delete all elements in articlelistpanels/labels and clear them (if vectors or lists or...)? Possibly, you need to call RemoveObject first. – Aconcagua May 09 '16 at 17:49
  • that also brought no effect, since the old components are still listed in `this->pnl_art_box` – Timo Treichel May 10 '16 at 09:42
  • Have you tried to simpy call `this->pnl_art_box->DestroyComponents();` or `this->pnl_art_box->DeleteChildren();` (not sure which one to prefer - tend to the latter one) instead of the for loop? If you do this repeatedly, be aware that the contents of your two lists will most probably get invalid! – Aconcagua May 10 '16 at 09:53
  • yes i did, none of them had the wanted effect ... i finally found the solution, it was `this->pnl_art_box->Components[i]->DisposeOf();` – Timo Treichel May 10 '16 at 09:59

1 Answers1

0

I finally found it by myself. The correct command had been:

for(int i = 1; i < this->pnl_art_box->ComponentCount; i++)
{
    this->pnl_art_box->Components[i]->DisposeOf();
}
Timo Treichel
  • 358
  • 3
  • 14