Frequently Asked Component Specific Questions

Options

Display all FAQ items

Search FAQ items:


Displaying items 1 to 1 of 1, page 1 of 1

<< previous next >>

TPlanner
Using TPlannerItem alarms

Through the Alarm property in a TPlannerItem and alarm handlers, all types of alarms can be triggered by the TPlannerItem. Note that alarms are enabled in the TPlanner by the property TPlanner.EnableAlarms. Different alarm handlers that play sound, send email, show a message, run a script, execute a program can be downloaded from https://www.tmssoftware.com/planaddon.htm

Example:

Following example creates a TPlannerItem in a day mode TPlanner that starts at 2AM and triggers an alarm message 30 minutes before the TPlannerItem starts :
with Planner1.CreateItem do 
begin 
  ItemStartTime := EncodeTime(2,0,0,0); // 02:00 AM 
  ItemEndTime := EncodeTime(3,0,0,0); // 03:00 AM 
  CaptionText := 'Item 1'; 
  Text.Text := 'This message tells the item starts in 30 minutes'; 
  CaptionType := ctText; 
  Alarm.Active := True; 
  Alarm.Handler := AlarmMessage1; 
  Alarm.TimeBefore := EncodeTime(0,30,0,0); // 30 minutes 
  Alarm.NotifyType := anNotes; 
end;
The item inserted in the TPlanner will thus trigger an alarm at 1.30AM . The AlarmMessage1 is a simple alarm handler that displays a message box. The selected text for the alarm message is the text of the TPlannerItem itself as selected by the NotifyType which is anNotes. At 1.30AM the message displayed is:

Alarm handlers are easy to write. An alarm handler descends for the TPlannerAlarmHandler class which is defined as:

TPlannerAlarmHandler = class(TComponent) 
public 
  function HandleAlarm(Address,Message:string; Tag, ID: Integer; Item: TPlannerItem): Boolean; virtual; 
end;
One single function should thus be defined. The result of the function indicates whether the alarm has been successfully handled or not. If the user selects for example to snooze the alarm for a given amount of time, return false, update the TPlannerItem.Alarm.TimeBefore property to the new time of the alarm and it will be triggered again. The Address, Message, Tag and ID parameters of this function are taken from the TPlannerItem.Alarm property.

The TAlarmMessage alarm handler defines this function in the following way:
{ TAlarmMessage } 
function TAlarmMessage.HandleAlarm(Address, Message: string; Tag, ID: Integer; Item: TPlannerItem): Boolean; 
begin 
  MessageDlg('Alarm for' +Item.CaptionText+#13+ HTMLStrip(Item.Text.Text),mtInformation,[mbok],0); Result := True; 
end;