unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Panel1: TPanel;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
PanelArry:Array[1..5] of TPanel;
end;
var
Form1: TForm1;
i:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
j:integer;
ExistsPanel:boolean;
begin
for i:=0 to 5 do
begin
if PanelArry[i]=nil then
begin
j:=i ;
ExistsPanel:=false;
break;
end
else
ExistsPanel:=true;
end;
if ExistsPanel then
begin
showmessage('Full,Genispan should learn more.');
exit;
end;
PanelArry[j]:=TPanel.Create(Self);
PanelArry[j].Left:= (j-1)*200;
PanelArry[j].Parent:=Self;
PanelArry[j].Caption:='Panel'+inttostr(i);
ListBox1.Items.Add(inttostr(j));
i:=i+1;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if ListBox1.ItemIndex<0 then
begin
showmessage('Choose a item in Listbox1,Genispan should be careful');
exit;
end;
PanelArry[strtoint(ListBox1.Items[ListBox1.ItemIndex])].Free;
ListBox1.Items.Delete(ListBox1.ItemIndex);
end;
end.