• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

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

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.

0
Alpha_AI
Asked:
Alpha_AI
2 Solutions
 
diniludCommented:
procedure TForm1.Button5Click(Sender: TObject);
var i:Integer;
begin
   for i:=0 to Panel1.ControlCount-1 do
   begin
      if Panel1.Controls[i] is TButton then
        TButton(Panel1.Controls[i]).Visible:=False;
   end;
end;
0
 
TheRealLokiSenior DeveloperCommented:
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
   begin
      if Panel1.Controls[i] is TButton then
        TButton(Panel1.Controls[i]).Free;
   end;

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
0

Featured Post

Technology Partners: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now