How does one use the DestroyComponents method

Posted on 2008-11-12
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
    LVL 36

    Accepted Solution

    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 36

    Assisted Solution

    by:Geert Gruwez

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

    Author Closing Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    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…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now