Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

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

Avatar of rfwoolf
rfwoolf
Flag of South Africa image

Use a TDateTimePicker as a control to pick a time. You can set the Kind property in the Object Inspector to Time.

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(DateTimePicker1.Time, now) < 5 then
  begin
   Timer1.enabled := false;
   Showmessage('Alarm!');
  end;
end;
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 :)
Avatar of Peter Kiers

ASKER

This is what i got but it doesn't work:

procedure TMainForm.DateTimePicker1Change(Sender: TObject);
begin
  AlarmDateTime := DateTimePicker1.Time
end;
(*----------------------------------------------*)
procedure TMainForm.StartBtnClick(Sender: TObject);
begin
    Timer1.enabled := True;
end;
(*----------------------------------------------*)
procedure TMainForm.Timer1Timer(Sender: TObject);
begin
  if SecondsBetween(AlarmDateTime, Now) < 5 then
   begin
   Timer1.enabled := false;
   Showmessage('Alarm!');
   end;
end;
(*----------------------------------------------*)

P.
What is not working?
You can do this for debugging:

procedure TMainForm.Timer1Timer(Sender: TObject);
begin
  MainForm.Caption := inttostr(SecondsBetween(AlarmDateTime, Now);
  if SecondsBetween(AlarmDateTime, Now) < 5 then
   begin
   Timer1.enabled := false;
   Showmessage('Alarm!');
   end;
end;
(*----------------------------------------------*)
I am testing it, and testing it but i still don't know why it isn't working!!!

P.
SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
timer interval = 1000
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of dinilud
dinilud
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It works now.

Thank you

Peter K.