delphi如何自动重启程序  
官方Delphi 学习QQ群: 682628230(三千人)\n
频道

delphi如何自动重启程序


思路1:
需要重启程序的时候,在onclose事件里面调用了一个批处理bat文件(AT 脚本);
然后在批处理文件里面加入适当延迟(比如2秒);通过批处理文件重新启动该程序;

思路2:
你另外写个小程序,用那个程序来启动你的程序

你的程序关闭时-》调用那个小程序
小程序启动你的程序(先判断程序是否已经关闭)
小程序自己关闭

在onclose里面
shellexecute(self.handle,nil,PChar('c:\小程序.exe'),nil,nil,sw_shownormal);

小程序的代码
在formcreate里面
shellexecute(self.handle,nil,PChar('c:\你的程序.exe'),nil,nil,sw_shownormal);
close;

思路3:
在退出前调用打开程序的语句,最简单

Application.Terminate;
winexec(Pchar(paramstr(0)), sw_show);

做成函数:
procedure KillApplication(Restart: boolean);
var
StartInfo: TStartupInfo;
ProcInfo: TProcessInformation;
begin
if Restart then
begin
GetStartupInfo(StartInfo);
FillChar(ProcInfo, SizeOf(TProcessInformation), #0);
CreateProcess(nil, GetCommandLine, nil, nil, False,
CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS, nil,
PChar(StartDir), StartInfo, ProcInfo);
end;
TerminateProcess(GetCurrentProcess, 1);
推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.050526142120361 seconds