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