Board index » cppbuilder » Deleting all sub(menu)items

Deleting all sub(menu)items

Hi,

I want to delete all subitems from a TMenuItem. What is the most efficient
way to do this? I tried the following:

while (AMenuItem->Count>0)
    AMenuItem->Delete(0);

But it does not work properly. Does anybody know what is going on?

Suggestions are very welcome,

Micha Nelissen.

 

Re:Deleting all sub(menu)items


Hi Micha,

Quote
> I want to delete all subitems from a TMenuItem. What is the most efficient
> way to do this?

You can use a little recursion to help you out here...

void DeleteAllChildren(TMenuItem *Item)
{
    while (Item->Count > 0)
    {
        TMenuItem *SubItem = Item->Items[0];
        DeleteAllChildren(SubItem);
        Item->Delete(0);
    }

Quote
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    DeleteAllChildren(AMenuItem);      

Quote
}

HTH.

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>
52064929

Re:Deleting all sub(menu)items


Hi Damon,

Quote
Damon Chandler wrote:
> HTH.

I made a mistake elsewhere, so that the menu was cleaned sometimes and
sometimes it wasn't.

Thanks for your time,

Micha Nelissen.

Other Threads