?
Solved

Advice which component to use

Posted on 2008-02-01
11
Medium Priority
?
160 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:peterkiers
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20795834
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
 
LVL 28

Expert Comment

by:2266180
ID: 20795881
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
 
LVL 1

Author Comment

by:peterkiers
ID: 20795895
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
LVL 13

Expert Comment

by:rfwoolf
ID: 20795919
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
 
LVL 1

Author Comment

by:peterkiers
ID: 20796017
I am testing it, and testing it but i still don't know why it isn't working!!!

P.
0
 
LVL 28

Assisted Solution

by:2266180
2266180 earned 400 total points
ID: 20796032
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
 
LVL 1

Author Comment

by:peterkiers
ID: 20796059
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
 
LVL 1

Author Comment

by:peterkiers
ID: 20796082
timer interval = 1000
0
 
LVL 13

Accepted Solution

by:
rfwoolf earned 800 total points
ID: 20796086
What is the value of the interval of your Timer unit in milliseconds?
e..g. 1000 milliseconds = 1 second
0
 
LVL 10

Assisted Solution

by:dinilud
dinilud earned 800 total points
ID: 20796304
Try like this

  if SecondsBetween(Timeof(AlarmDateTime),Time) < 5 then
   begin
   Timer1.enabled := false;
   Showmessage('Alarm!');
   end;
0
 
LVL 1

Author Comment

by:peterkiers
ID: 20796333
It works now.

Thank you

Peter K.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question