我想实现一个定时器,每天某个固定时间,譬如说中午12:00或是00:00,就触发一个事件,怎样写定时器?有点象定时器。
最近小弟delphi新手入门,感觉delphi的帮助实在和MSDN的帮助相去甚远,哪位大虾再给个好点的教材、帮助?多谢了先!

解决方案 »

  1.   

    if (now()=strtotime('12:20')) or (now()=strtotime('24:00'))   then
        showmessage('dfasdf');
      

  2.   

    做个系统的计划任务,把程序放进去
    或者timer每秒触发一次,取得当前时间,如果条件相符就执行设定程序
    方法是多种多样的。
      

  3.   

    放一个timer组件,
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    if (now()=strtotime('12:00')) or (now()=strtotime('00:00'))   then
        showmessage('快给我加分了');end;
      

  4.   

    各位老大不觉得每秒都执行一个事件很浪费么?
    我在C语言下的做法时:
    1、取得当前时间;
    2、计算得出到定时器设定时间的差并设为定时器的internal;
    3、启动定时器;
    4、在OnTimer事件里重启一次定时器。按照这个思路的话,如果一天一次闹钟,我一天处理一次就足够了。按照每秒算一次的方案,您一天得处理多少次?60*60*24!!!!
    而且每秒起一次定时器的方法我也会的,只不过觉得太土,所以不好意思往上贴,所以才请教各位高人的。
      

  5.   

    1、取得当前时间;
    var
      nowtime:string;
    begin
       nowtime:= FormatDateTime('hh:nn:ss',now());
    end;2、计算得出到定时器设定时间的差并设为定时器的internal;
    (假设为12:00:00)var
      thetime:string;
      hh:integer;
      nn:integer;
      ss:integer;
      thesec:integer;  //总秒数
      
      hh:=strtoint(copy(nowtime,1,2))-strtoint(copy(thetime,1,2));
      nn:=strtoint(copy(nowtime,4,2))-strtoint(copy(thetime,4,2));
      ss:=strtoint(copy(nowtime,7,2))-strtoint(copy(thetime,7,2));  thesec:=hh*3600+nn*60+ss;3.启动定时器;
    timer1.enable:=true;4、在OnTimer事件里重启一次定时器。timer1.enable:=false;
    timer1.enable:=true;
    详细的自已要补充喔。
      
      

  6.   

    认同tongki_8(矛盾与迟钝) 与楼主,但考虑delphi的时钟并不太准,而且触发其他事件需要处理时间,这样做是否误差比较大?
      

  7.   

    今天试了一下delphi的定时器,按每秒1次事件来算,采用每次累加的方法,每累加到10分钟就去执行一个事件,同时记录下当前时间,结果发现,执行几遍之后,就出现了定时器消息丢失的情况。
    代码如下:
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      time1:TDateTime;
      str:String;
    begin
      time1 := Time;
      str := TimeToStr(time1);
      Label7.Caption := str;
      
      if bSyncStartFlag then
      begin
        internal := internal + 1;
        if internal = 60*10 then
        begin
          time1 := Time;
          str := TimeToStr(time1);
          Label7.Caption := str;
          str := 'start sync at '+ str;
          OutputLog(str);
          dosometing;
          internal := 0;
        end;  end
      else
      begin    if str = '18:00:00' then
          begin
            bSyncStartFlag := true;
            str := 'start sync at '+ str;
            OutputLog(str);
            dosometing;
          end;
      end;
    以第一次事件从18:00:00开始计算,第二次就不准了,第二次的时间为18:10:03,说明漏了三个定时器消息,巨晕倒。
      

  8.   

    timer每秒触发一个事件绝不可取,自己用就算了,给别人用那绝对是害人。
    semigroup的主意倒是不错
      

  9.   

    用windows的定时计划(叫什么?)服务?
    你用timer客户就会买菜刀去的
      

  10.   

    semigroup() 我想要,我是刚开始学的,希望以后一起进步
    e-mail:[email protected]