What is the best way to autostart an action after OnShow event?

前端 未结 3 1347
梦毁少年i
梦毁少年i 2020-12-15 23:14

I have a small application that most of the time have an action behind a Start-button that should be triggered from the commandline parameter /AUTORUN. If that parameter is

3条回答
  •  囚心锁ツ
    2020-12-15 23:43

    In the FormShow post yourself a message. In the message handler run your btnStart.

    TfrmMainForm = class(TForm)
    // snip
    private
      procedure AutoStart(var Message: TMessage); message wm_user;
    // snip
    end
    
    procedure TfrmMainForm.FormShow(Sender: TObject);
    begin
      if FindCmdLineSwitch('AUTORUN') then
        PostMessage(Handle, wm_user, 0, 0);
    end;
    
    procedure TfrmMainForm.AutoStart(var Message: TMessage);
    begin
      btnStart.Click;
    end;
    

提交回复
热议问题