I have a panel which has an editbox on it and I want to know how to remove everything off the panel control

Posted on 2007-07-27
Last Modified: 2010-04-05
I have a panel which has an editbox on it
and I want to know how do I remove everything off the panel control
when i click a button.

like is there a way to detach the controls off the panel thats matches objects of class TButton?
without going through each button1.visible := false; button2.visible := false;

and so on.

Question by:Alpha_AI
    LVL 10

    Assisted Solution

    procedure TForm1.Button5Click(Sender: TObject);
    var i:Integer;
       for i:=0 to Panel1.ControlCount-1 do
          if Panel1.Controls[i] is TButton then
    LVL 17

    Accepted Solution

    since you say you wish to "remove" the controls, I'll expand on dinilud's answer.
    you would do

       for i:=pred(Panel1.ControlCount) downto 0  do
          if Panel1.Controls[i] is TButton then

    and if you simply wanted to move them to another panel, you would replace the last line with
            TButton(Panel1.Controls[i]).Parent := SomeOtherPanel;

    The reason I use pred downto 0 is because you would be removing items from the same list you are searching through, and you'd get an index out of range error otherwise

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    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…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    734 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

    24 Experts available now in Live!

    Get 1:1 Help Now