我是这样写的:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if now=datetimepicker1.Time then
begin
timer1.Enabled:=false;
showmessage(timetostr(datetimepicker1.Time)+'到了!');
timer1.Destroy;
end;
end;为什么showmessage(timetostr(datetimepicker1.Time)+'到了!');始终无法执行?请问代码该如何写?
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if now=datetimepicker1.Time then
begin
timer1.Enabled:=false;
showmessage(timetostr(datetimepicker1.Time)+'到了!');
timer1.Destroy;
end;
end;为什么showmessage(timetostr(datetimepicker1.Time)+'到了!');始终无法执行?请问代码该如何写?
解决方案 »
- 版主来看一下,为什么别人提交的FAQ通过审核后都加信誉分,我怎么不加?
- 关于Access数据库数据对比问题
- 求adotable或adoquery的添加语句
- 哪有下关于基于SQL数据库delphi编程的书的?
- 请问:DELPHI与ACCESS97数据库连接成功,但运行时出现无法输入数据的错误提示:
- COM组件如何封装成ActiveX
- 求助:怎么每次预览都只有第一条记录?
- 急!Delphi连接Sql Server数据库表只能看到第一列
- tstringgrid的drawcell过程到底是怎么回事?
- 请问哪里有delphi5的补丁下载?
- stringgrid更新多条数据到access
- cxGrid1DBBandedTableView1.DataController.SetValue 的问题
begin
if timetostr(now)=timetostr(datetimepicker1.Time) then
begin
timer1.Enabled:=false;
showmessage(timetostr(datetimepicker1.Time)+'到了!');
timer1.Destroy;
end;
end;
DateUtils;function TimeOf(const AValue: TDateTime): TDateTime;
谢谢了,我试了不行啊。procedure TForm1.Timer1Timer(Sender: TObject);
begin
if TimeOf(now)=datetimepicker1.Time then
begin
timer1.Enabled:=false;
showmessage(timetostr(datetimepicker1.Time)+'到了!');
timer1.Destroy;
end;
end;
//delphi 7procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);
procedure DecodeDateTime(const AValue: TDateTime; out AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word);
分别比较小时、分钟、秒,就可以了。
直接用frac(Now)取得的就是当前时间(相对的,用trunc(Now)取得的就是当前日期),但是这仍然不能用来比较,因为里面包含了毫秒等信息。所以有两种方法,一是就像你现在一样,格式化成字符串来比较,二就是像7楼一样,把时间信息拆开来,独立比较时、分、秒等你需要比较的部分。
var
Year, Month, Day: Word;
Hour, Min, Sec, MSec: Word;
s:string;
begin
DecodeDate(Date, Year, Month, Day);
DecodeTime(Time, Hour, Min, Sec, MSec);
s:=format('%.2d%.2d%.2d%.2d%.2d',[Year, Month, Day,Hour, Min]);//年,月,日,时,分
if s='要比较的时间' then
begin
//处理事件
end;
end;
不用那么麻烦的,用formatdatetime函数来格式化就行了。