For this you need something to check from time to time.
A unique routine that does not repeat itself will not serve.
A simple way to do this is to use the component Timer of Delphi.
It is in the tab System of the component pallet.
Here:
Or here, depending on the version of Delphi and the layout you are using:
So just add this component to your Form and make sure the property Enable is True.
If you need accuracy at the time of execution, then your interval (property Interval) shall be equal to 1000.
Once done, just double-click the component Timer to create its main method, which is of the event Ontimer.
So you need to write the routine of this method:
procedure TMeuForm.timerTarefaTimer(Sender: TObject);
begin
if Time = StrToTime('18:00:00') then
btnTarefa.Click;
// ou btnTarefaClick(nil);
end;
Thus, with 1000 milliseconds set in the Inverval of the component Timer, you will have the process running at exactly 18hrs as reported in the code.
If you don’t need accuracy at runtime and just want to have a task run close to that time, then you can save on check cycles from Timer as follows:
Since you intend to report an inverting equal to 60000 (60 thousand milliseconds = 60 min. = 1 hour) you can do so:
Add to your Form a variable that will store the date and time of the last day the task was executed.
private
FUltimaExecucao: TDate;
end;
It can be started with zero.
procedure TMeuForm.FormCreate(Sender: TObject);
begin
FUltimaExecucao := 0;
end;
And then perform your verification as follows:
procedure TMeuForm.timerTarefaTimer(Sender: TObject);
begin
if (Time >= StrToTime('18:00:00')) and (Time <= StrToTime('19:00:00')) and
(FUltimaExecucao < Date)then
begin
btnTarefa.Click;
// ou btnTarefaClick(nil);
FUltimaExecucao = Date;
end;
end;
Thus, you will not have accuracy of the time that was executed, but will have fewer cycles of component execution Timer.
@Tiago, that’s right, will be a FORM with a TIMER that every day at 18:00hrs he should just click on a button Button2.click, that’s all it is.
– user7605