关闭并重新启动DELPHI中的当前应用程序

DRo*_*kie 19 delphi restart

我怎么能这样做?

由于某种原因或用户选择,"询问"当前应用程序是否自行重启.

And*_*and 29

uses ShellAPI;

...

procedure TForm1.RestartThisApp;
begin
  ShellExecute(Handle, nil, PChar(Application.ExeName), nil, nil, SW_SHOWNORMAL);
  Application.Terminate; // or, if this is the main form, simply Close;
end;
Run Code Online (Sandbox Code Playgroud)

  • 如果您只允许1个应用程序实例,这也无效 (3认同)
  • 这会“重新启动并关闭”,而不是相反(意味着发生**资源共享**而不是**资源释放**) (2认同)
  • 如果您使用仅为应用程序知道的命令行参数(例如'-newinstance'),@ simon相对容易解决,这将阻止启动时进行多个实例检查. (2认同)