Delphi MDIChild form flashes when opening in modal mode

1

I have a form MDIChild that I open as follows:

Application.CreateForm(TfrmManProduto, frmManProduto);

However, sometimes I need this form in modal ... with some tips I adapted my code as follows for open it in modal mode:

Application.CreateForm(TfrmManProduto, frmManProduto);  
frmManProduto.FormStyle   := fsNormal;                 
frmManProduto.Visible     := False;
frmManProduto.Position    := poMainFormCenter;
frmManProduto.ShowModal;

That way it works, but it blinks until it shows on the screen.

I wonder if there is any way to not flash / display the form until you get to call frmManProduto.ShowModal ;

    
asked by anonymous 09.11.2018 / 12:39

1 answer

2

Set the Visible and FormStyle property of the form to False and fsNormal , respectively, by default, and create a constructor method that receives a parameter indicating whether the form will modal or not, more or less :

type
  TfrmManProduto = class(TForm)
  public
    constructor Create(AOwner: TComponent; isModal: Boolean); reintroduce;
  end;

implemetation

TfrmManProduto.Create(AOwner: TComponent; isModal: Boolean);
begin
  inherited Create(AOwner);

  Position := poMainFormCenter;

  if not (isModal) then
  begin
    FormStyle := fsMDIChild;
    Visible := True;
  end;
end;

To create the form would look like this:

frmManProduto := TfrmManProduto.Create(Application, True);
frmManProduto.ShowModal();
    
09.11.2018 / 12:50