如何定期执行一个功能.(50分)

  • 主题发起人 主题发起人 floppy
  • 开始时间 开始时间
F

floppy

Unregistered / Unconfirmed
GUEST, unregistred user!
&nbsp; &nbsp;有个程序,其要求在程序运行时,每正点打印一次,(如12:00,13:00...)<br>&nbsp; &nbsp; 该如何作呢?
 
最简单的是设个timer, 每秒种判断一次时间, 如果是正点则调用打印功能.<br><br>可以将这段程序放入一个Thread 中以防止由于当前程序太忙而无法响应.<br>调用打印推荐方法:让timer发送自定义消息给主进程, 主进程再通过不同方法<br>调用具体打印模块(直接调用或者线程调用).
 
如果不用timer, 就用win带的schedule task也行.<br>timer时间设成离下一分钟差的秒数吧:-)<br>
 
如果你用Delphi5,下面使用Help中的例子拼的一个程序,少做修改不难达到目的。<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; Label2: TLabel;<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; DateTime : TDateTime;<br>&nbsp; str : string;<br>begin<br>&nbsp; DateTime := Time; &nbsp;// store the current date and time<br>&nbsp; str := TimeToStr(DateTime); // convert the time into a string<br>&nbsp; Caption := str; &nbsp;// display the time on the form's caption<br>&nbsp; { Note This could have been done with the following line of code:<br>&nbsp; &nbsp; Caption := TimeToStr(Time); }<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; Present: TDateTime;<br>&nbsp; Year, Month, Day, Hour, Min, Sec, MSec: Word;<br>&nbsp;begin<br>&nbsp; Present:= Now;<br>&nbsp; DecodeDate(Present, Year, Month, Day);<br>&nbsp; Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '<br>&nbsp; &nbsp; + IntToStr(Month) + ' of Year ' + IntToStr(Year);<br>&nbsp; DecodeTime(Present, Hour, Min, Sec, MSec);<br>&nbsp; Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '<br>&nbsp; &nbsp; + IntToStr(Hour);<br>end;<br>
 
做一个delphi的打印程序,然后设置win95 or win98 的电源及屏保,<br>最后在 windows 的计划任务下添加次打印程序,设置每正点执行。<br>&nbsp; 此致
 
Timer 配合 取系统时间的function time 即可搞掂!
 
先将打印程序编译成.exe,然后单击windows下‘计划任务’,<br>单击‘添加已计划的任务’,按向导提示执行,最后打开此<br>计划任务的属性做修改。 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 
多人接受答案了。
 
后退
顶部