如何设置一个任意时间间隔的定时任务 比如说时间间隔为1小时,2小时,1分钟,10分钟,30分钟等等任意时间的间隔,这个时间可以自己随意设置。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个时间要自己设定的,是任意的可以随意设置的,相当于是做任务调度。不是在Timer中定一个时间就完了。 timer的间隔定位1000,即1秒然后在事件里对全局变量(form的属性ft)加1,再根据设定的时间数x(30分钟=30*60)判断if ft>=x thenbegin ft:=0; 做设定的事情end;如果同时监控几个任务,就多加几个属性ft1,ft2,... procedure TFormMain.SpeedStartClick(Sender: TObject);begin if (strtoint(SpinHour.Text)>=24) or (strtoint(SpinHour.Text)<=0) then begin showmessage('请正确设置时间!'); exit; end; if RadioHour.Checked then begin TimerHour.Enabled:=true; StrFSDTime := FormatDateTime('hhmm', now()); FlagDs := False; end; if RadioMinute.Checked then begin FlagDs := False; StrFSDTime := FormatDateTime('nn', now()); TimerMinute.Enabled := True; end; SpeedStart.Enabled := false; SpeedStop.Enabled := true;end;procedure TFormMain.SpeedStopClick(Sender: TObject);begin TimerHour.Enabled:=false; TimerMinute.Enabled := false; SpeedStart.Enabled := true; SpeedStop.Enabled := false;end;procedure TFormMain.TimerHourTimer(Sender: TObject);begin if FlagDs = True then exit; //判定是否开始 if FormatDateTime('hhmm', now()) = StrFSDTime then begin FlagDs := true; showmessage(SpinHour.Text); StrFSDTime := FormatDateTime('hhmm', inchour(now(), StrToint(SpinHour.Text))); FlagDs := False; end;end;procedure TFormMain.TimerMinuteTimer(Sender: TObject);begin if FlagDs = True then exit; //判定是否开始 if FormatDateTime('nn', now()) = StrFSDTime then begin FlagDs := true; showmessage(StrFSDTime); StrFSDTime := FormatDateTime('nn', incMinute(now(), StrToint(SpinMinute.Text))); FlagDs := False; end;end;end.我是这么做的,在设置小时的时候如果是24小时就会定时不准确。期待高手帮忙解决一下,非常感谢。 关于FASTREPORT 的问题 用什么的控件能实现显示数据库中的信息 请指点 Listbox里的items里的 Delimiter 是怎么用的 有关报表套打的问题。 关于参数传值和传引用的问题. 菜鸟基础问题,散分~~~~~~~~~~~~~~ 关于DataSet的Cancel或DataBase的RollBack问题 请教关于控件的几个问题。 请教数据库的问题。 我谁有DBF数据库的修复工具 DBGRID中数据每次查询都覆盖了,怎样不覆盖 ? Delphi中关于数据库集组件的使用
然后在事件里对全局变量(form的属性ft)加1,再根据设定的时间数x(30分钟=30*60)判断
if ft>=x then
begin
ft:=0;
做设定的事情
end;如果同时监控几个任务,就多加几个属性ft1,ft2,...
begin
if (strtoint(SpinHour.Text)>=24) or (strtoint(SpinHour.Text)<=0) then
begin
showmessage('请正确设置时间!');
exit;
end;
if RadioHour.Checked then
begin
TimerHour.Enabled:=true;
StrFSDTime := FormatDateTime('hhmm', now());
FlagDs := False;
end;
if RadioMinute.Checked then
begin
FlagDs := False;
StrFSDTime := FormatDateTime('nn', now());
TimerMinute.Enabled := True;
end;
SpeedStart.Enabled := false;
SpeedStop.Enabled := true;
end;procedure TFormMain.SpeedStopClick(Sender: TObject);
begin
TimerHour.Enabled:=false;
TimerMinute.Enabled := false;
SpeedStart.Enabled := true;
SpeedStop.Enabled := false;
end;
procedure TFormMain.TimerHourTimer(Sender: TObject);
begin
if FlagDs = True then exit; //判定是否开始
if FormatDateTime('hhmm', now()) = StrFSDTime then
begin
FlagDs := true;
showmessage(SpinHour.Text);
StrFSDTime := FormatDateTime('hhmm', inchour(now(), StrToint(SpinHour.Text)));
FlagDs := False;
end;
end;
procedure TFormMain.TimerMinuteTimer(Sender: TObject);
begin
if FlagDs = True then exit; //判定是否开始
if FormatDateTime('nn', now()) = StrFSDTime then
begin
FlagDs := true;
showmessage(StrFSDTime);
StrFSDTime := FormatDateTime('nn', incMinute(now(), StrToint(SpinMinute.Text)));
FlagDs := False;
end;
end;
end.
我是这么做的,在设置小时的时候如果是24小时就会定时不准确。期待高手帮忙解决一下,非常感谢。