-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_dlg.pas
128 lines (97 loc) · 2.52 KB
/
time_dlg.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
unit time_dlg;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
Menus, DateUtils;
type
{ TfrmTimeDlg }
TfrmTimeDlg = class(TForm)
btn_ok: TButton;
btn_abort: TButton;
edt_hr_in: TEdit;
edt_min_in: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ud_hour: TUpDown;
ud_minute: TUpDown;
procedure edt_hr_inChange(Sender: TObject);
procedure edt_min_inChange(Sender: TObject);
procedure ud_hourClick(Sender: TObject; Button: TUDBtnType);
procedure ud_minuteClick(Sender: TObject; Button: TUDBtnType);
function GetResult(): TDateTime;
constructor Create(hour, min: Integer);
private
public
end;
var
frmTimeDlg: TfrmTimeDlg;
implementation
{$R *.lfm}
{ TfrmTimeDlg }
constructor TfrmTimeDlg.Create(hour, min: Integer);
begin
inherited Create(nil);
edt_hr_in.Text := IntToStr(hour);
edt_min_in.Text := IntToStr(min);
end;
function Wrap(n, min, max: Integer): Integer;
begin
if n > max then Result := (min - 1) + (n - max)
else if n < min then Result := max
else Result := n;
end;
procedure TfrmTimeDlg.ud_hourClick(Sender: TObject; Button: TUDBtnType);
begin
if Button = btNext then
begin
edt_hr_in.Text := IntToStr(Wrap(StrToInt(edt_hr_in.Text) + 1, 0, 23));
end
else
begin
edt_hr_in.Text := IntToStr(Wrap(StrToInt(edt_hr_in.Text) - 1, 0, 23));
end;
end;
procedure TfrmTimeDlg.edt_hr_inChange(Sender: TObject);
var num: Integer;
begin
if edt_hr_in.Text = '' then exit();
try
num := StrToInt(edt_hr_in.Text);
if (num < 0) or (num > 23) then edt_hr_in.Text := '0';
except
edt_hr_in.Text := '';
end;
end;
procedure TfrmTimeDlg.edt_min_inChange(Sender: TObject);
var num: Integer;
begin
if edt_min_in.Text = '' then exit();
try
num := StrToInt(edt_min_in.Text);
if (num < 0) or (num > 59) then edt_min_in.Text := '0';
except
edt_min_in.Text := '';
end;
end;
procedure TfrmTimeDlg.ud_minuteClick(Sender: TObject; Button: TUDBtnType);
begin
if Button = btNext then
begin
edt_min_in.Text := IntToStr(Wrap(StrToInt(edt_min_in.Text) + 1, 0, 59));
end
else
begin
edt_min_in.Text := IntToStr(Wrap(StrToInt(edt_min_in.Text) - 1, 0, 59));
end;
end;
function TfrmTimeDlg.GetResult(): TDateTime;
var time: TDateTime;
begin
if edt_hr_in.Text = '' then edt_hr_in.Text := '0';
if edt_min_in.Text = '' then edt_min_in.Text := '0';
time := EncodeTime(StrToInt(edt_hr_in.Text), StrToInt(edt_min_in.Text), 0, 0);
exit(time);
end;
end.