-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsdpStopwatch.pas
61 lines (50 loc) · 1.64 KB
/
sdpStopwatch.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Ìîäóëü, ðåàëèçóþùèé îáúåêò-ñåêóíäîìåð.
// Âåðñèÿ äëÿ Delphi 5 è 32-õ ðàçðÿäíûõ ïðîöåññîðîâ.
// Àâòîð: Ñèäîðîâ Ä. Ï.
unit sdpStopwatch;
interface
type
// Ñåêóíäîìåð
TStopwatch = class
procedure Start; // Çàïóñêàåò ñåêóíäîìåð
procedure Stop; // Îñòàíàâëèâàåò ñåêóíäîìåð
function GetValueStr: String; // Çàìåðåííîå âðåìÿ â âèäå ñòðîêè
function GetValueMSec: Cardinal; // Çàìåðåííîå âðåìÿ â ìèëëèñåêóíäàõ
private
StartTime: TDateTime; // Âðåìÿ çàïóñêà ñåêóíäîìåðà
StopTime: TDateTime; // Âðåìÿ îñòàíîâêè ñåêóíäîìåðà
end;
implementation
uses
SysUtils;
// ****************************************************************************
// ********** Ìåòîäû îáúåêòà TStopwatch **********
// ****************************************************************************
procedure TStopwatch.Start;
begin
StartTime := Time;
end;
procedure TStopwatch.Stop;
begin
StopTime := Time;
end;
function TStopwatch.GetValueStr: String;
var
Value: TDateTime;
Hour, Min, Sec, MSec: Word;
begin
Value := StopTime - StartTime;
DecodeTime(Value, Hour, Min, Sec, MSec);
Result := IntToStr(Hour) + ':' + IntToStr(Min) + ':' + IntToStr(Sec) + '.' +
IntToStr(MSec);
end;
function TStopWatch.GetValueMSec: Cardinal;
var
Value: TDateTime;
Hour, Min, Sec, MSec: Word;
begin
Value := StopTime - StartTime;
DecodeTime(Value, Hour, Min, Sec, MSec);
Result := 3600*1000*Hour + 60*1000*Min + 1000*Sec + MSec;
end;
end.