Added OnSample event. V0.0.2

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3530 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
gbamber
2014-09-08 11:59:16 +00:00
parent 6b5cc615d3
commit 5279284bf0
5 changed files with 520 additions and 472 deletions

View File

@ -1,7 +1,7 @@
object mainform: Tmainform object mainform: Tmainform
Left = 1162 Left = 1050
Height = 264 Height = 264
Top = 272 Top = 186
Width = 437 Width = 437
BorderIcons = [biSystemMenu, biMinimize] BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle BorderStyle = bsSingle
@ -59,6 +59,7 @@ object mainform: Tmainform
ClientHeight = 158 ClientHeight = 158
ClientWidth = 180 ClientWidth = 180
TabOrder = 4 TabOrder = 4
OnClick = crp_SetTimerClick
object Label1: TLabel object Label1: TLabel
Left = 16 Left = 16
Height = 15 Height = 15
@ -146,13 +147,28 @@ object mainform: Tmainform
end end
end end
object LongTimer1: TLongTimer object LongTimer1: TLongTimer
About.Description.Strings = (
'LongTimer is a descendent of TIdleTimer'#13#10'and shares its properties and methods.'#13#10#13#10'Additional properties affect when the'#13#10'OnTimer event is fired.'#13#10#13#10'With LongTimer, the OnTimer event'#13#10'will be fired only ONCE - every time'#13#10'the interval that you set is reached.'
)
About.Title = 'About TLongTimer Component'
About.Height = 380
About.Width = 320
About.Font.Color = clNavy
About.Font.Height = -13
About.BackGroundColor = clWindow
About.Version = '0.0.1'
About.Authorname = 'Gordon Bamber'
About.Organisation = 'Public Domain'
About.AuthorEmail = 'minesadorada@charcodelvalle.com'
About.ComponentName = 'TLongTimer'
About.LicenseType = abLGPL
Enabled = False Enabled = False
OnTimer = LongTimer1Timer OnTimer = LongTimer1Timer
OnStartTimer = LongTimer1StartTimer OnStartTimer = LongTimer1StartTimer
OnStopTimer = LongTimer1StopTimer OnStopTimer = LongTimer1StopTimer
IntervalType = lt3Monthly Daily24Hour = 0
Daily24Hour = 10
WeeklyDay = lt3Wednesday WeeklyDay = lt3Wednesday
OnSample = LongTimer1Sample
left = 8 left = 8
top = 8 top = 8
end end

View File

@ -31,7 +31,9 @@ type
procedure cmb_Daily24HourChange(Sender: TObject); procedure cmb_Daily24HourChange(Sender: TObject);
procedure cmb_IntervalTypeChange(Sender: TObject); procedure cmb_IntervalTypeChange(Sender: TObject);
procedure cmb_weekordateChange(Sender: TObject); procedure cmb_weekordateChange(Sender: TObject);
procedure crp_SetTimerClick(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure LongTimer1Sample(Sender: TObject);
procedure LongTimer1StartTimer(Sender: TObject); procedure LongTimer1StartTimer(Sender: TObject);
procedure LongTimer1StopTimer(Sender: TObject); procedure LongTimer1StopTimer(Sender: TObject);
procedure LongTimer1Timer(Sender: TObject); procedure LongTimer1Timer(Sender: TObject);
@ -55,7 +57,7 @@ implementation
procedure Tmainform.LongTimer1Timer(Sender: TObject); procedure Tmainform.LongTimer1Timer(Sender: TObject);
begin begin
// memo_ReportTimerEvent.Lines.Add('LastFired at ' + FormatDateTime('hh:nn:ss', LongTimer1.LastFired)); // memo_ReportTimerEvent.Lines.Add('LastFired at ' + FormatDateTime('hh:nn:ss', LongTimer1.LastFired));
memo_ReportTimerEvent.Lines.Add('Fired at ' + FormatDateTime('hh:nn:ss', Now)); memo_ReportTimerEvent.Lines.Add('Timer fired at ' + FormatDateTime('hh:nn:ss dd-mm-yyyy', Now));
end; end;
procedure Tmainform.FormCreate(Sender: TObject); procedure Tmainform.FormCreate(Sender: TObject);
@ -81,15 +83,19 @@ begin
cmb_SampleInterval.ItemIndex:=2; cmb_SampleInterval.ItemIndex:=2;
end; end;
procedure Tmainform.LongTimer1Sample(Sender: TObject);
begin
memo_ReportTimerEvent.Lines.Add('Sampled at ' + FormatDateTime('hh:nn:ss',Now));
end;
procedure Tmainform.LongTimer1StartTimer(Sender: TObject); procedure Tmainform.LongTimer1StartTimer(Sender: TObject);
begin begin
// memo_ReportTimerEvent.Lines.Add('Timer running'); Self.Caption:='Timer was started at ' + FormatDateTime('dd/mm/yyyy hh:nn:ss',Now);
end; end;
procedure Tmainform.LongTimer1StopTimer(Sender: TObject); procedure Tmainform.LongTimer1StopTimer(Sender: TObject);
begin begin
// memo_ReportTimerEvent.Lines.Add('Timer stopped'); Self.Caption:=Application.Title;
end; end;
procedure Tmainform.cmd_StopTimerClick(Sender: TObject); procedure Tmainform.cmd_StopTimerClick(Sender: TObject);
@ -114,7 +120,7 @@ procedure Tmainform.cmb_Daily24HourChange(Sender: TObject);
begin begin
LongTimer1.Daily24Hour:=cmb_Daily24Hour.ItemIndex; LongTimer1.Daily24Hour:=cmb_Daily24Hour.ItemIndex;
end; end;
procedure Tmainform.PopulateWeekOrDate(Const i:Integer); procedure Tmainform.PopulateWeekOrDate(const i: Integer);
// 0=Weekly, 1=Monthly // 0=Weekly, 1=Monthly
Var iMonthDay:Integer; Var iMonthDay:Integer;
@ -170,5 +176,10 @@ begin
end; end;
end; end;
procedure Tmainform.crp_SetTimerClick(Sender: TObject);
begin
end;
end. end.

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0"?>
<CONFIG> <CONFIG>
<Package Version="4"> <Package Version="4">
<PathDelim Value="\"/> <PathDelim Value="\"/>
@ -19,8 +19,8 @@
</CompilerOptions> </CompilerOptions>
<Description Value="TLongTimer is a descendant of TIdleTimer that samples every 30minutes when idle. <Description Value="TLongTimer is a descendant of TIdleTimer that samples every 30minutes when idle.
It is intended for TTrayIcon applications. DailyHour is a 24-hour clock (16 = 4pm) and MonthlyDate is best &lt; 29 "/> It is intended for TTrayIcon applications. DailyHour is a 24-hour clock (16 = 4pm) and MonthlyDate is best &lt; 29 "/>
<License Value="LGPLv2"/> <License Value="LGPL"/>
<Version Release="1"/> <Version Release="2"/>
<Files Count="2"> <Files Count="2">
<Item1> <Item1>
<Filename Value="ulongtimer.pas"/> <Filename Value="ulongtimer.pas"/>
@ -35,7 +35,7 @@ It is intended for TTrayIcon applications. DailyHour is a 24-hour clock (16 = 4
</Files> </Files>
<i18n> <i18n>
<EnableI18N Value="True"/> <EnableI18N Value="True"/>
<OutDir Value="lang_longtimer"/> <OutDir Value="locale"/>
<EnableI18NForLFM Value="True"/> <EnableI18NForLFM Value="True"/>
</i18n> </i18n>
<Type Value="RunAndDesignTime"/> <Type Value="RunAndDesignTime"/>

View File

@ -44,18 +44,22 @@ type
fTday:TDay; fTday:TDay;
fHourDone,fDayDone,fDateDone:Boolean; fHourDone,fDayDone,fDateDone:Boolean;
fSampleInterval:TSampleInterval; fSampleInterval:TSampleInterval;
fVersion:String;
fOnSample:TNotifyEvent;
Procedure SetDay(aDay:TDay);
Procedure SetDailyHour(aHour:Word);
Procedure SetMonthlyDate(ADate:Word);
procedure SetSampleInterval(ASampleInterval:TSampleInterval);
protected protected
{ Protected declarations } { Protected declarations }
procedure DoOnIdle(Sender: TObject; var Done: Boolean); override; procedure DoOnIdle(Sender: TObject; var Done: Boolean); override;
procedure DoOnIdleEnd(Sender: TObject); override; procedure DoOnIdleEnd(Sender: TObject); override;
procedure DoOnTimer;override; procedure DoOnTimer;override;
Procedure SetDay(aDay:TDay);
Procedure SetDailyHour(aHour:Word);
Procedure SetMonthlyDate(ADate:Word);
procedure SetSampleInterval(ASampleInterval:TSampleInterval);
public public
{ Public declarations } { Public declarations }
constructor Create(TheOwner: TComponent); override; constructor Create(TheOwner: TComponent); override;
// Until the first Timer event, this will be the component's creation time
Property LastFired:TDateTime read fLastFiredDateTime;
published published
{ Published declarations } { Published declarations }
// Default=false // Default=false
@ -80,10 +84,12 @@ type
Property Daily24Hour:Word read fHour write SetDailyHour; Property Daily24Hour:Word read fHour write SetDailyHour;
// You can also set the Hour as well as the Weekday // You can also set the Hour as well as the Weekday
Property WeeklyDay:TDay read fTDay write SetDay; Property WeeklyDay:TDay read fTDay write SetDay;
// You can also set the hour as well as the date // You can also set the Hour as well as the date
property MonthlyDate:Word read fDate write SetMonthlyDate default 1; property MonthlyDate:Word read fDate write SetMonthlyDate default 1;
// Until the first Timer event, this will be the component's creation time // Version string of this component
Property LastFired:TDateTime read fLastFiredDateTime; property Version:String read fVersion;
// Fired every time LongTimer samples
Property OnSample:TNotifyEvent read fOnSample write fOnSample;
end; end;
procedure Register; procedure Register;
@ -91,6 +97,12 @@ procedure Register;
implementation implementation
CONST CONST
C_OneMinute = 60000; C_OneMinute = 60000;
C_Version='0.0.2';
(*
V0.0.1: Initial commit
V0.0.2: Added OnSample event
V0.0.3: ??
*)
procedure Register; procedure Register;
begin begin
RegisterComponents('System',[TLongTimer]); RegisterComponents('System',[TLongTimer]);
@ -127,10 +139,14 @@ begin
fDateDone:=False; fDateDone:=False;
fCurrentDateTime:=Now; fCurrentDateTime:=Now;
fLastFiredDateTime:=Now; fLastFiredDateTime:=Now;
// Set defaults for properties
fDate:=1; fDate:=1;
fSampleInterval:=lt3Every10Minutes; fSampleInterval:=lt3Every10Minutes;
Interval:=10 * C_OneMinute; Interval:=10 * C_OneMinute;
fIntervalType:=lt1Daily; fIntervalType:=lt1Daily;
fVersion:=C_Version;
end; end;
procedure TLongTimer.DoOnIdle(Sender: TObject; var Done: Boolean); procedure TLongTimer.DoOnIdle(Sender: TObject; var Done: Boolean);
begin begin
@ -155,6 +171,7 @@ begin
DecodeTime(fCurrentDateTime,cH,cMi,cS,cmS); DecodeTime(fCurrentDateTime,cH,cMi,cS,cmS);
cDay:=DayOfTheMonth(fCurrentDateTime); cDay:=DayOfTheMonth(fCurrentDateTime);
// Split LastFired date into parts
DecodeDate(fLastFiredDateTime,lY,lM,lD); DecodeDate(fLastFiredDateTime,lY,lM,lD);
DecodeTime(fLastFiredDateTime,lH,lMi,lS,lmS); DecodeTime(fLastFiredDateTime,lH,lMi,lS,lmS);
lDay:=DayOfTheMonth(fLastFiredDateTime); lDay:=DayOfTheMonth(fLastFiredDateTime);
@ -177,6 +194,8 @@ begin
fHourDone:=FALSE; fHourDone:=FALSE;
end; end;
// Fire the OnSample event?
If Assigned(fOnSample) then fOnSample(Self);
// Only proceed further at specified interval in specified hour - else exit // Only proceed further at specified interval in specified hour - else exit
If (fIntervalType = lt1Daily) and ((fHourDone = TRUE) OR (cH <> fHour)) then Exit; If (fIntervalType = lt1Daily) and ((fHourDone = TRUE) OR (cH <> fHour)) then Exit;
@ -224,6 +243,7 @@ begin
fHourDone := TRUE; fHourDone := TRUE;
end; end;
end; end;
procedure TLongTimer.SetSampleInterval(ASampleInterval:TSampleInterval); procedure TLongTimer.SetSampleInterval(ASampleInterval:TSampleInterval);
Var TimerEnabled:Boolean; Var TimerEnabled:Boolean;
Begin Begin
@ -262,6 +282,7 @@ begin
DaySunday = 7; DaySunday = 7;
} }
end; end;
Procedure TLongTimer.SetDailyHour(aHour:Word); Procedure TLongTimer.SetDailyHour(aHour:Word);
Var TimerEnabled:Boolean; Var TimerEnabled:Boolean;
begin begin