如何让程序中的一段代码在一天中指定的时刻执行一次(如每天23:00显示一对话框)

解决方案 »

  1.   

    用一Timer不停地获取系统时间,,,等到你规定的如23点就调用一程序嘛
      

  2.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
    MyTime:string;
    begin
      Timer1.Interval:=10000;//每十秒检测一次系统时间
      MyTime:=FormatDateTime('hh:nn',now);
      if MyTime='23:00' then
      ShowMessage('到时间睡觉了!');
    end;
      

  3.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
    MyTime:string;
    begin
      Timer1.Interval:=1000;//每秒检测一次系统时间
      MyTime:=FormatDateTime('hh:mm:ss',now);
      if MyTime='23:00:00' then
      ShowMessage('到时间干活了!');
    end;
      

  4.   

    是不是可以节省一下呢?
    用两个Timer,Timer1,Timer2,
    其中Timer2.Interval:=1000;初始Timer2.Enabled := False;
    先用Timer1获取一次时间,然后判断当前时间与指定时间的差,
    然后指定Timer1的Interval属性为这个'差'减1000,待到再次触发Timer1时,使Timer2 Enable
    在Timer2中触发事件,然后Timer2.Enabled := False