Delphi xe10.1中实现程序的自重启

delphi5年前 (2020)发布 admin
625 0

uses ShellAPI;

代码如下

procedure TForm2.btn1Click(Sender: TObject);
var
  strAppPath: String;
begin
form1.qry1.UpdateBatch;//提交修bai改;
ShowMessage('更新数据,需要重启程序使程序加载更新后的数据');
  strAppPath := application.ExeName;
    application.Terminate;
    ShellExecute(Handle, nil,pchar(Application.ExeName),'','', 0);
end;

参照:https://bbs.csdn.net/topics/60218231

整合了二楼三楼的代码,他俩的代码我在xe10.1中可以执行就是同时会有两个程序在执行,整合后完美自重启。

二楼

procedure TForm1.ReCallSelf;
var
  strAppPath: String;
begin
    strAppPath := application.ExeName;
    application.Terminate;
    WinExec(PChar(strAppPath), SW_SHOW);
end;
三楼
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShellExecute(Handle, nil,pchar(Application.ExeName),'','', 0);
  Close;
end;

© 版权声明

相关文章