Link to home
Start Free TrialLog in
Avatar of bilgehanyildirim
bilgehanyildirim

asked on

Reminder with delphi

Hi,
is it possible to write a reminder with delphi. It will work like this. user will create reminders like
12/11/2006  12:12:25  Meeting with Rob
and all these will be kept in the DB.
When the time comes, the system will pop up and will remind the user.

ignore the db implementation, all i need is the timer-schedule module.
Thanks!
Avatar of sun4sunday
sun4sunday
Flag of India image

You can use a timer and trigger the query in a specific time intervel and check any reminder exists. If exists pop up the reminder.
Make sure that all the reminders are set in a time interval of few minutes. Atleast 10 or 15 or 30 minutes. (don't set the timer for the user in seconds) If you are providing the time(split into 30 minutes), then you have to do a timer with 30 minutes time interval and when it reach 30 minutes do the query and reset the timer.


If you really want the time interval very less like (1 minutes) store one hour reminders in locally (may be in array) and check the array each minutes. Once one hour reach, do the query and fill the next hours reminder. Also when any reminder add/edit, query the reminder for that hour to refelct the updates of the reminder

sun4sunday
Avatar of Wim ten Brink
You might just add a task to Windows Task Scheduler. See http://windowssdk.msdn.microsoft.com/en-us/library/ms725268.aspx for a start. The API for Delphi can be found at http://cc.borland.com/Item.aspx?id=16007 in case you think it is a usable solution.
The other solution is indeed to use a timer, checking at regular intervals if it's about time or not. In general, you can check every second if you like, to get your triggered at exactly the right time, but in that case you have to quickly check the time in your code and exit the code if it's not yet time immediately. Else it will eat too many precious clock cycles.

To check for the proper time, retrieve the earliest time from your database and keep comparing to that time. Don't start checking for any of the other times!!! At the beginning of your application, read the earliest reminder and store it in-memory. Then you can close the database connection as far as the application is concerned since you won't need further access until that time has been reached. Once the time is reached, determine the next earliest reminder and start processing the current reminder. (Open and close the database if need be.) Once the current reminder is processed, your application can wait until it's time for the next reminder.

If you add reminders to the database, you might want to send a message to your application that it should update the earliest reminder time that it has stored. Yet whatever you do, avoid database access in your timer event since it will slow down your process enormously.

If done correctly, you can check every second and still use 0% of the CPU according to the task manager. If you keep checking with the database, your CPU usage might be around the 10% all the time, unless you check a lot less often...
As for the implementation of the timer module I guess you would have to do tne next steps:
declare variables for the on timer event:
var
 h,m,s,ms:Word;
begin
// here check the current time:
DecodeTime(Now,h,m,s,ms);

// all you need to do next is to retrieve from the database the times that fit the current time and execute the reminders.
retrieval from database could look like:
Select * from remindertable where hour(remtimer)=h and minute(remtimer)=m
// or you could build the time using the variables and compare the time directly.
// the time can be built as string if you want to:
// timex:=IntToStr(h)+':'+IntToStr(m)+':'+IntToStr(s);


Or variations of this depending on the database used.
Also do not forget to place some Application.ProcessMessages in the timer, in order to unfreeze the application while stuff is executed.


regards
Also you might be interested in using the nice conversion tools offered by delphi:
StrToTime(string)  -> time
TimeToStr(datetime) ->string

Also for the same purpose check the datetime routines of delphi. A lot of nice and handy functions there.
ASKER CERTIFIED SOLUTION
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand 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