Board index » cppbuilder » Removing all objects on a parent control

Removing all objects on a parent control

Hello,

I have some code that creates a TButton and adds it to a parent TPanel for
each logical drive found in the system. What I need to know is how I can
remove all buttons from the panel. At runtime, the name of the dynamically
created button is DriveButton, but I don't know what the name of the control
is when I try to remove it using Panel->RemoveControl()

Thanks,

Aaron

 

Re:Removing all objects on a parent control


Quote
Aaron Bockover <abockover> wrote in message news:3b4e0c46_2@dnews...
> Hello,

> I have some code that creates a TButton and adds it to a parent
TPanel for
> each logical drive found in the system. What I need to know is how I
can
> remove all buttons from the panel. At runtime, the name of the
dynamically
> created button is DriveButton, but I don't know what the name of the
control
> is when I try to remove it using Panel->RemoveControl()

From what you wrote, I suspect that a more robust design would use a
list in your code that is filled when each button is created.  For one
thing, suppose a button that's *not* a drive button is added to the
control by the next fellow on the project...

But in answer to your question, look at the Controls property of the
Panel.  You can iterate through it, and dynamic_cast each control to
<TButton *> to see (if non-null result) the control being tested is a
TButton.  Then you can destroy the button.  It would be better if the
buttons were created with a NULL Owner, since you have promised to
delete them.

As I said, I don't care for this, but something like:

..for loop on i  but note that ControlCount changes when there are
deletions!
TButton *AsButton = dynamic_cast<TButton *>(myPanel->Controls[i]);
 if (AsButton != NULL) // Was cast successful?
    {
    ...check Properties of AsButton to make sure it's a drive button
    ...delete it *and otherwise cleanup*
    }

--
Timothy H. Buchman
========================================
City Center Theater New York NY
tbuchmanPLEASE(at sign)REMOVEcitycenter.org
Please treat this signature information as confidential.
========================================
Search .borland newsgroup archives at:
http://www.mers.com/searchsite.html

Re:Removing all objects on a parent control


No matter what the control is, I want it removed when I call the function I
have created "RemoveButton()".
I just want to delete anything on the panel.

Thanks,

Aaron

Other Threads