procedure TForm1.ClearPanel(Sender: TObject);
var
i: integer;
c: TComponent;
begin
for i := componentcount - 1 downto 0 do
begin
c := component[i];
if TControl(c).parent = sender then
c.free;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
ClearPanel(Panel1);
end;