我有一个带有pagecontrol的主形式(frmmain(。PageControl在启动时以几种形式填充,让我们说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相对应的单上调用on Activate方法,因此我尝试了;
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
我找到了一个解决方案:
with pagecontrol1 do
begin
with tform(activepage.controls[0]) do
if assigned(onactivate) then
onactivate(self);
end;