在delphi中如何让程序自动重启

在delphi中如何让程序自动重启,第1张

根据我的经验,可考虑三种方法:

一是将离去某程序的命令放到循环体内,为避免运行出错死循环,套上tryexcept end。

二团棚神是在调用和友单元窗体上加上个TIMER控件,通过时间设置定时运行。

三是开动你的脑筋,根据需求做个触发程序块,满足条件就启动该塌亏程序。

procedure TForm1.Button1Click(Sender: TObject)

begin

timer1.Interval:=60*1000 //启动监控,每1分钟检查一次设定时间和当前时间

timer1.Enabled:=true

endprocedure TForm1.Timer1Timer(Sender: TObject)

var

l_time: TDateTime

h_time: TDateTime

ss:Int64

begin

timer1.enabled:=false

h_time:= strtotime('10:30:00')

l_Time := time //now是取当前的日期加时间,time只取当前时间

if (h_time>l_time) then begin

ss:=SecondsBetween(h_time,l_time)//求两袜掘拦个时间相差多少秒

if ss<5*60 then begin //如果时间间隔小于5分钟定时启动timer2

timer1.Enabled:=false

showmessage('Inteval seconds:'+inttostr(ss))

timer2.Interval:=ss*1000

timer2.Enabled:=true

end

end

else

timer1.enabled:=true

endprocedure TForm1.Timer2Timer(Sender: TObject)

begin

timer2.enable:=false

showmessage('ok on time run the program')

timer1.Enabled:=true //再次开始监控

end自己加入要散唤执行程序的代码...或者用Timer2替掉也告胡行实现

你可以在程序亩扰运行时自动写入注册表

uses中悔枝包含 Registry

var

MyFilePath:String

begin

MyFilePath:=Application.ExeName

MyReg:=TRegistry.Create

MyReg.RootKey:= HKEY_CURRENT_USER

MyReg.OpenKey('SoftWare\Microsoft\Windows\CurrentVersion\Run'碧耐敏,True)

MyReg.WriteString ('myfile',MyFilePath )

MyReg.Free

这样做,一般会有杀毒软件进行拦截,需要同意才行。

你还可以直接把程序放到开始菜单中的启动下。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12415390.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-23
下一篇2023-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存