Delphi onshow main form / modal form

前端 未结 3 1567
情歌与酒
情歌与酒 2021-02-04 16:57

I have a project which has a main form and some other forms. When the app loads it needs to carry out some tasks and show the results in a modal form on top of the main form. T

3条回答
  •  -上瘾入骨i
    2021-02-04 17:23

    One commonly used option is to post yourself a message in the form's OnShow. Like this:

    const
      WM_SHOWMYOTHERFORM = WM_USER + 0;
    
    type
      TMyMainForm = class(TForm)
        procedure FormShow(Sender: TObject);
      protected
        procedure WMShowMyOtherForm(var Message: TMessage); message WM_SHOWMYOTHERFORM;
      end;
    
    ...
    
    
    procedure TMyMainForm.FormShow(Sender: TObject);
    begin
      PostMessage(Handle, WM_SHOWMYOTHERFORM, 0, 0);
    end;
    
    procedure TMyMainForm.WMShowMyOtherForm(var Message: TMessage);
    begin
      inherited;
      with TMyOtherForm.Create(nil) do begin
        try
          ShowModal;
        finally
          Free;
        end;
      end;
    end;
    

提交回复
热议问题