Line | |
---|
1 | unit Common.Delay;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, DateUtils;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
30 | implementation
|
---|
31 |
|
---|
32 | { TDelay }
|
---|
33 |
|
---|
34 | function TDelay.GetEnabled: Boolean;
|
---|
35 | begin
|
---|
36 | Result := FEnabled;
|
---|
37 | end;
|
---|
38 |
|
---|
39 | function TDelay.GetOwerflowed: Boolean;
|
---|
40 | begin
|
---|
41 | Result := ((Now - StartTime) > (Duration * OneMillisecond)) and FEnabled;
|
---|
42 | end;
|
---|
43 |
|
---|
44 | function TDelay.GetRunning: Boolean;
|
---|
45 | begin
|
---|
46 | Result := ((Now - StartTime) <= (Duration * OneMillisecond)) and FEnabled;
|
---|
47 | end;
|
---|
48 |
|
---|
49 | procedure TDelay.SetEnabled(const AValue:Boolean);
|
---|
50 | begin
|
---|
51 | FEnabled := True;
|
---|
52 | end;
|
---|
53 |
|
---|
54 | procedure TDelay.Start;
|
---|
55 | begin
|
---|
56 | StartTime := Now;
|
---|
57 | FEnabled := True;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | procedure TDelay.Stop;
|
---|
61 | begin
|
---|
62 | FEnabled := False;
|
---|
63 | end;
|
---|
64 |
|
---|
65 | constructor TDelay.Create;
|
---|
66 | begin
|
---|
67 | Duration := 1000;
|
---|
68 | StartTime := 0;
|
---|
69 | FEnabled := False;
|
---|
70 | end;
|
---|
71 |
|
---|
72 | end.
|
---|
Note:
See
TracBrowser
for help on using the repository browser.