How does one use the DestroyComponents method

Posted on 2008-11-12
Medium Priority
Last Modified: 2013-11-23
I dynamically create a whole lot of TPanels on a parent panel called for example PlanPnl.  When I want to draw a new set of panels on the same parent panel, I call PlanPnl.DestroyComponents to first remove the previous set of panels from the parent.  However after calling PlanPnl.DestroyComponents, the children panels remain on the parent panel.  What must I do to clear the parent panel?
Question by:HenryM2
  • 2
LVL 38

Accepted Solution

Geert Gruwez earned 1000 total points
ID: 22947658
DestroyComponents destroys all owned components, not the contained ones
The components on the Panel are owned by the form, and the parent is the panel

use below function as:

procedure TForm.ShowPlanPnl;
  // Add components here
procedure DestroyChildren(AWinControl: TWinControl);
var I: Integer;
  aChild: TControl;
  for I := AWinControl.ControlCount-1 to 0 do
    aChild := AWinControl.Controls[I];

Open in new window

LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 1000 total points
ID: 22948276

for I := AWinControl.ControlCount-1 downto 0 do

Author Closing Comment

ID: 31516119
Sorry for only getting back now, I was away. Solution works perfectly, thanks.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question