看看下面的例子就可以了:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
btnAdd: TButton;
btnDelete: TButton;
procedure btnAddClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
private
ButtonArray:array of TButton;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.btnAddClick(Sender: TObject);
var
i:integer;
begin
SetLength(ButtonArray,5);
for i := 0 to 4do
begin
ButtonArray := TButton.Create(Self);
ButtonArray.Top := 10 + i * 30;
ButtonArray.Left := 30;
ButtonArray.Height := 20;
ButtonArray.Width := 50;
ButtonArray.Parent := Self;
ButtonArray.Show;
end;
end;
procedure TForm1.btnDeleteClick(Sender: TObject);
var
i:integer;
begin
SetLength(ButtonArray,5);
for i := 0 to 4do
begin
ButtonArray.Free;
end;
end;
end.