确定activepage中的哪个表单,delphi

时间:2017-04-18 14:54:06

标签: delphi pagecontrol

我有一个带有pagecontrol的mainform(frmMain)。页面控件在启动时通过几种形式填充,让我们说Form1,Form2和Form3

procedure TForm1.FormCreate(Sender: TObject);
begin
   ManualDock(frmMain.PageControl1);
   show;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
   ManualDock(frmMain.PageControl1);
   show;
end;
procedure TForm3.FormCreate(Sender: TObject);
begin
   ManualDock(frmMain.PageControl1);
   show;
end;

这很有效。 当我然后更改activepage时,我想在对应于activepage的表单上调用OnActivate方法,所以我尝试了这个;

procedure TfrmMain.PageControl1Change(Sender: TObject);
begin
  with pagecontrol1 do
  begin
     lbHeading.Caption := activepage.Caption;
     with tform(activepage) do        // <= This does 
     if assigned(onactivate) then     // <= not
     onactivate(self);                // <= work
  end;
end;

Activepage的类型为TTabsheet

1 个答案:

答案 0 :(得分:1)

我找到了解决方案:

with pagecontrol1 do
begin
  with tform(activepage.controls[0]) do
  if assigned(onactivate) then
  onactivate(self);
end;