[英]How to handle OnTimer event in Delphi XE2?
I need to show a message say "Hi" everyday at 9 AM. 我需要每天上午9点显示一条消息“嗨”。 Do I require Timer for this?
我需要Timer吗? How can I check whether its 9 AM or not.
我怎样才能检查是否是上午9点。 What should be the interval of timer at which
OnTimer
event run? OnTimer
事件运行的计时器间隔应该是多少?
procedure Form1.TimerTimer1(Sender: TObject);
begin
ShowMessage("Hi");
end;
If I run this event in after 24 hours, I fear it might pass 9 AM and will not fire. 如果我在24小时后举办此活动,我担心它可能会在上午9点过去而不会开火。
Unless you have other valid reasons, it's far more easier to 除非你有其他正当理由,否则要容易得多
你可以使用类似CRON的Delphi解决方案: http : //www.cromis.net/blog/downloads/cron-scheduler/
As the answerers before me said, there are better and easier ways. 正如我之前的回答者所说,有更好更容易的方法。 Suppose you want to do this your way, in Delphi, then yes, you need a timer.
假设您想按照Delphi的方式执行此操作,那么是的,您需要一个计时器。 The needed steps are:
所需的步骤是:
Write the handler for OnTimer: 编写OnTimer的处理程序:
procedure Form1.TimerTimer1(Sender: TObject); var x:TDateTime begin x:=Now; if {the hour read is 9 and minute is 0} then ShowMessage("Hi"); end;
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.