Form1
uses unit2;
procedure TForm1.FormCreate(Sender: TObject);
begin
form2 := TForm2.Create(Panel,self);
form2.BorderStyle := bsNone;
form2.Windowstate := wsMaximized;
form2.Parent := Panel;
form2.Show;
end;
Form2
uses Unit1;
private
FOwnerForm : TForm;
end;
constructor Create(AOwner: TComponent; OwnerForm: TForm ); reintroduce;//響應父窗體事件的關鍵
constructor TForm2.Create(AOwner: TComponent; OwnerForm: TForm);
begin
inherited Create(Aowner);
FOwnerForm := OwnerForm;
end;
事件觸發(在FORM2中來響應FORM1的事件)
procedure TForm2.Button1Click(Sender: TObject);
begin
if Self.FOwnerForm.ClassType = TForm1 then
begin
ShowMessage('按下我了!');
end;
end;