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

LVL 1
peterkiersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rfwoolfCommented:
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;
0
2266180Commented:
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 :)
0
peterkiersAuthor Commented:
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.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

rfwoolfCommented:
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;
(*----------------------------------------------*)
0
peterkiersAuthor Commented:
I am testing it, and testing it but i still don't know why it isn't working!!!

P.
0
2266180Commented:
well, tell us what you get or don't get and what you are expecting.

what is the interval of your timer? if you place a breakpoint in your timer, what's the value of AlarmDateTime?

does the caption of the form change according to the timers interval? (decreasing every x seconds with x seconds?)
0
peterkiersAuthor Commented:
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.
0
peterkiersAuthor Commented:
timer interval = 1000
0
rfwoolfCommented:
What is the value of the interval of your Timer unit in milliseconds?
e..g. 1000 milliseconds = 1 second
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
diniludCommented:
Try like this

  if SecondsBetween(Timeof(AlarmDateTime),Time) < 5 then
   begin
   Timer1.enabled := false;
   Showmessage('Alarm!');
   end;
0
peterkiersAuthor Commented:
It works now.

Thank you

Peter K.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.