var
Fbutton2:Tbutton;//手动添加的两个button对象
Fbutton3:Tbutton;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Fbutton2 := Tbutton.Create(form1); //创建对象的同时制定了拥有者form1
Fbutton2.Parent := form1; //同时还要指定控制者,否者将不会显示;这里讲form1同时指定为了控制者
Fbutton2.Caption := 'button2';
Fbutton2.Top := 30;
Fbutton2.Height := 40;
Fbutton2.Width := 60;
Fbutton3 := Tbutton.Create(form1);
Fbutton3.Top := 80;
Fbutton3.Height := 40;
Fbutton3.Width := 60;
Fbutton3.Parent := Panel1;
Fbutton3.Caption := 'button3';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Fbutton2.Free; //这里是手动释放,当然也可以不手动释放,等 Fbutton2的拥有者form1释放之前会检测Fbutton2是否释放,
// 如果已经手动释放将不再释放,如果没有将会进行释放,
end;
Fbutton2:Tbutton;//手动添加的两个button对象
Fbutton3:Tbutton;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Fbutton2 := Tbutton.Create(form1); //创建对象的同时制定了拥有者form1
Fbutton2.Parent := form1; //同时还要指定控制者,否者将不会显示;这里讲form1同时指定为了控制者
Fbutton2.Caption := 'button2';
Fbutton2.Top := 30;
Fbutton2.Height := 40;
Fbutton2.Width := 60;
Fbutton3 := Tbutton.Create(form1);
Fbutton3.Top := 80;
Fbutton3.Height := 40;
Fbutton3.Width := 60;
Fbutton3.Parent := Panel1;
Fbutton3.Caption := 'button3';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Fbutton2.Free; //这里是手动释放,当然也可以不手动释放,等 Fbutton2的拥有者form1释放之前会检测Fbutton2是否释放,
// 如果已经手动释放将不再释放,如果没有将会进行释放,
end;