Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a delphi application (that's running) to do something at a particular time/date

Tags:

delphi

My application sits in the system tray when it's not being used.

The user can configure events to occur at particular schedule. For example they may way the task performed mon-fri at 5pm or every wednesday at 3pm or on the 16th of every month at 10am.

Assuming my delphi program is always running, it starts at boot-up, what is the best way in delphi to support the triggering of these scheduled events.

Obviously a TTimer can be used to schedule events based on elapsed time but they don't seem suited to this problem.

Cheers

like image 629
SamH Avatar asked Jan 10 '10 15:01

SamH


4 Answers

You can use my CRON compliant Cromis Scheduler (link to archive.org). It even supports some things that cron does not. Interval based events for instance and from / to timeframe. I use it in a lot of my software and it has proven itself quite useful. It is free, very lightweight, works in threads and is production tested. If you need any further help just mail me.

The other ways would be:

  1. Use windows scheduling API as already suggested. But this may change between OS-es.
  2. Use JCL that has a scheduler unit (component in the JVCL), but I found that one hard to use from code directly. That is why I wrote my own.
like image 74
Runner Avatar answered Nov 09 '22 21:11

Runner


I would use the Microsoft Task Scheduler API for that:

http://msdn.microsoft.com/en-us/library/aa383614(VS.85).aspx

There are Delphi Wrappers available for the API if you don't want to do the "dirty work", but I don't know if there's a free one. You might have a look at

  • http://www.sicomponents.com/taskscheduler.html
  • http://www.torry.ru/pages.php?id=296

If you don't want to use the Microsoft Scheduler, there are things like the CronJob Component available here: http://www.appcontrols.com/components.html. It's shareware, too, but is easy to implement (just an onAlert event).

like image 35
Leo Avatar answered Nov 09 '22 20:11

Leo


You need a scheduling component. There are many available, however I can't seem to find any free one. You can always build one yourself, based on TTimer, or try to access theTask Scheduling API.

However, having a timer that executes a task every minute to check if a task is due, is much simpler.

like image 25
Kornel Kisielewicz Avatar answered Nov 09 '22 20:11

Kornel Kisielewicz


You could implement some kind of inter process communication in your program and trigger these events via ipc by a program called from the Windows scheduling service. This approach has the advantage that you don't need to write a user interface to set up the schedule and also that ipc might prove useful in other ways.

like image 1
dummzeuch Avatar answered Nov 09 '22 21:11

dummzeuch