如何在绘制表单之前检查表单是否为模态表单?

Fab*_*zio 4 forms delphi

我的一些表单可以显示为正常形式和模态形式。如果它们显示为模态形式,我必须隐藏一些在模态状态下无用的组件。

if(fsModal in Self.FormState) then
begin 
  //hiding some components...
end;
Run Code Online (Sandbox Code Playgroud)

我想在绘制表单之前执行我的代码,以避免不必要地多次绘制。

Dsm*_*Dsm 6

我以为OnShow在表单可见之前执行,但似乎并非如此。所以你可以这样做:

TMyForm = class( TForm )  // this will already be in your source
public
  function ShowModal: Integer; override;
end;

function TMyForm.ShowModal: Integer;
begin
  // hide some components
  Result := inherited;
  // show them again in case next time it is a Show
end;
Run Code Online (Sandbox Code Playgroud)

您不能以相同的方式覆盖 Show - 您必须覆盖visible 属性,以便更轻松地重置组件的可见性,如图所示。