source: trunk/Packages/Common/Common.Delay.pas

Last change on this file was 30, checked in by chronos, 6 months ago
  • Modified: Updated Common package.
File size: 1.3 KB
Line 
1unit Common.Delay;
2
3interface
4
5uses
6 Classes, SysUtils, DateUtils;
7
8type
9 { TDelay }
10
11 TDelay = class
12 private
13 FEnabled: Boolean;
14 function GetEnabled:Boolean;
15 function GetOwerflowed:Boolean;
16 function GetRunning: Boolean;
17 procedure SetEnabled(const AValue: Boolean);
18 public
19 StartTime: TDateTime;
20 Duration: Integer; // ms
21 procedure Start;
22 procedure Stop;
23 constructor Create;
24 property Overflowed: Boolean read GetOwerflowed;
25 property Running: Boolean read GetRunning;
26 property Enabled: Boolean read GetEnabled write SetEnabled;
27 end;
28
29
30implementation
31
32{ TDelay }
33
34function TDelay.GetEnabled: Boolean;
35begin
36 Result := FEnabled;
37end;
38
39function TDelay.GetOwerflowed: Boolean;
40begin
41 Result := ((Now - StartTime) > (Duration * OneMillisecond)) and FEnabled;
42end;
43
44function TDelay.GetRunning: Boolean;
45begin
46 Result := ((Now - StartTime) <= (Duration * OneMillisecond)) and FEnabled;
47end;
48
49procedure TDelay.SetEnabled(const AValue:Boolean);
50begin
51 FEnabled := True;
52end;
53
54procedure TDelay.Start;
55begin
56 StartTime := Now;
57 FEnabled := True;
58end;
59
60procedure TDelay.Stop;
61begin
62 FEnabled := False;
63end;
64
65constructor TDelay.Create;
66begin
67 Duration := 1000;
68 StartTime := 0;
69 FEnabled := False;
70end;
71
72end.
Note: See TracBrowser for help on using the repository browser.