放一个Timer,然后 procedure TForm1.Timer1Timer(Sender: TObject); var wHour,wMin,wSec,wMSec : Word; begin DecodeTime(Time,wHour,wMin,wSec,wMSec); if (wHour = 9) and (wMin = 0) and (wSec = 0) then ShowMessage('9点了') end;
procedure TForm1.Timer1Timer(Sender: TObject); begin if Time=StrToTime('13:32:50') then //StrToTime(TimeStr)then showmessage('Success!'); end;procedure TForm1.FormCreate(Sender: TObject); begin Timer1.Enabled:=true; end; 这样写对吗?(好像有一次成功的) 可是为什么到这个时间,也没有showmessage呢?
"可是为什么到这个时间,也没有showmessage呢?" Time是实数类型,用“=”做条件当然很难碰巧精确相等。何况,那段检测的代码并非一直在执行。改成(Time >= ...) and (Time <= ...)这样的形式就不会有问题。
楼上的说得没错 用Timer是非精确性的 最好条件用 >= and <=
定时器 procedure TForm1.Timer1Timer(Sender: TObject); begin if Time=StrToTime('13:32:50') 执行你想要执行的功能如果你想时间精确到毫秒的话,你可以设成毫秒。 如果用在服务器上的话就不能用窗体了写个配子文件就行了
procedure TForm1.Timer1Timer(Sender: TObject);
var
wHour,wMin,wSec,wMSec : Word;
begin
DecodeTime(Time,wHour,wMin,wSec,wMSec);
if (wHour = 9) and (wMin = 0) and (wSec = 0) then ShowMessage('9点了')
end;
B、在WINDOWS的任务中添加一条任务,任务位置在%INSTALL%\TASK下以文件方式存在。
如果要在程序运行的过程中也要判断呢,那应该如何写呢??
begin
if Time=StrToTime('13:32:50') then //StrToTime(TimeStr)then
showmessage('Success!');
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=true;
end;
这样写对吗?(好像有一次成功的)
可是为什么到这个时间,也没有showmessage呢?
Time是实数类型,用“=”做条件当然很难碰巧精确相等。何况,那段检测的代码并非一直在执行。改成(Time >= ...) and (Time <= ...)这样的形式就不会有问题。
用Timer是非精确性的
最好条件用 >= and <=
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Time=StrToTime('13:32:50')
执行你想要执行的功能如果你想时间精确到毫秒的话,你可以设成毫秒。
如果用在服务器上的话就不能用窗体了写个配子文件就行了