本例子为在Form1的Panel中显示Form2窗体,请注意例子中的reintroduce关键字
//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;
关键字词: