Peter Kiers
asked on
Advice which component to use
Dear Experts,
This is what I want my programm to do:
A user enters 3 timestamps in the 3 editboxes.
for example: edit1: 13:00, edit2: 14:00 and edit3: 15:00
By clicking on a button, a Timer will be activated and the
timer checks if the systemtime is equal as the time of one
of the 3 editboxes, if so then give a beep.
What component can I use best for the user to enter a timestamp?
And can someone help me to make a beginning.
Grtz,
PK
This is what I want my programm to do:
A user enters 3 timestamps in the 3 editboxes.
for example: edit1: 13:00, edit2: 14:00 and edit3: 15:00
By clicking on a button, a Timer will be activated and the
timer checks if the systemtime is equal as the time of one
of the 3 editboxes, if so then give a beep.
What component can I use best for the user to enter a timestamp?
And can someone help me to make a beginning.
Grtz,
PK
I would use anotehjr approach (the component is fine).
I would calculate the seconds from "now" (the now function) and all the 3 datetimepickers and maybe store them into an array;
then get the minimum value, set the timer interval to that minimum value, remove the min value from the list and start the timer. when timer fires, do the abopve operation again until the list is empty.
it's much more optimal then making the timer fire at every x seconds :)
I would calculate the seconds from "now" (the now function) and all the 3 datetimepickers and maybe store them into an array;
then get the minimum value, set the timer interval to that minimum value, remove the min value from the list and start the timer. when timer fires, do the abopve operation again until the list is empty.
it's much more optimal then making the timer fire at every x seconds :)
ASKER
This is what i got but it doesn't work:
procedure TMainForm.DateTimePicker1C hange(Send er: TObject);
begin
AlarmDateTime := DateTimePicker1.Time
end;
(*------------------------ ---------- ---------- --*)
procedure TMainForm.StartBtnClick(Se nder: TObject);
begin
Timer1.enabled := True;
end;
(*------------------------ ---------- ---------- --*)
procedure TMainForm.Timer1Timer(Send er: TObject);
begin
if SecondsBetween(AlarmDateTi me, Now) < 5 then
begin
Timer1.enabled := false;
Showmessage('Alarm!');
end;
end;
(*------------------------ ---------- ---------- --*)
P.
procedure TMainForm.DateTimePicker1C
begin
AlarmDateTime := DateTimePicker1.Time
end;
(*------------------------
procedure TMainForm.StartBtnClick(Se
begin
Timer1.enabled := True;
end;
(*------------------------
procedure TMainForm.Timer1Timer(Send
begin
if SecondsBetween(AlarmDateTi
begin
Timer1.enabled := false;
Showmessage('Alarm!');
end;
end;
(*------------------------
P.
What is not working?
You can do this for debugging:
procedure TMainForm.Timer1Timer(Send er: TObject);
begin
MainForm.Caption := inttostr(SecondsBetween(Al armDateTim e, Now);
if SecondsBetween(AlarmDateTi me, Now) < 5 then
begin
Timer1.enabled := false;
Showmessage('Alarm!');
end;
end;
(*------------------------ ---------- ---------- --*)
You can do this for debugging:
procedure TMainForm.Timer1Timer(Send
begin
MainForm.Caption := inttostr(SecondsBetween(Al
if SecondsBetween(AlarmDateTi
begin
Timer1.enabled := false;
Showmessage('Alarm!');
end;
end;
(*------------------------
ASKER
I am testing it, and testing it but i still don't know why it isn't working!!!
P.
P.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When i set the timer at 15:00 and when the system timer is 15:00 also
the counter in the caption of the mainform stop counting for a couple of seconds
and the continues. But nothing happens. My showmessage doesn't work or a beep.
P.
the counter in the caption of the mainform stop counting for a couple of seconds
and the continues. But nothing happens. My showmessage doesn't work or a beep.
P.
ASKER
timer interval = 1000
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It works now.
Thank you
Peter K.
Thank you
Peter K.
Set your TTimer's interval to the number of seconds between each check, for example 1000 for 1 second. (Technically you might decide to check only every 5 seconds, or 15 seconds, etc).
Then double-click on the timer to edit its OnTimer event, and say something like this
uses
DateUtils <--- add dateutils to the uses clause of your unit
begin
If secondsbetween(DateTimePic
begin
Timer1.enabled := false;
Showmessage('Alarm!');
end;
end;