procedure TForm1.Button1Click(Sender: TObject);
var
form2: TForm2;//子窗体
begin
if Panel1.FindChildControl('Form2') <> nil then
exit;
form2 := TForm2.Create(self);
form2.Parent := Panel1;
form2.Show;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
cnl: TControl;
begin
cnl := Panel1.FindChildControl('Form2');
if cnl <> nil then
FreeAndNil(cnl);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
form2: TForm2;//子窗体
begin
if Panel1.FindChildControl('Form2') <> nil then
exit;
if not Assigned(Form2) then
form2 := TForm2.Create(self);
try
form2.Parent := Panel1;
form2.Show;
finally
Form2 := nil ; //最好是在 Form2的Destory事件里写
end ;
end;