-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINTINPUT.BAK
110 lines (96 loc) · 2.04 KB
/
INTINPUT.BAK
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
unit InputInt;
interface
uses
Objects, Views, Dialogs, MsgBox;
type
Interval = (a_b, a_inf, inf_b, inf_inf);
PInputInt = ^TInputInt;
TInputInt = object(TInputLine)
min, max: LongInt;
int: Interval;
constructor Init(R: TRect; i: integer; mina, maxa: longint);
function DataSize: word; virtual;
procedure GetData(var Rec); virtual;
procedure SetData(var Rec); virtual;
function Valid(com: word): boolean; virtual;
end;
implementation
constructor TInputInt.Init(R: TRect; i: integer; mina, maxa: longint);
begin
TInputLine.Init(R, i);
min := mina;
max := maxa;
if min < max then
int := a_b
else if min = max + 3 then
int := inf_inf
else if min = max + 1 then
int := a_inf
else
int := inf_b;
end;
function TInputInt.DataSize: word;
begin
DataSize := SizeOf(LongInt);
end;
procedure TInputInt.GetData(var Rec);
var
R: LongInt absolute Rec;
i: integer;
begin
if Valid(i) then
val(Data^, R, i);
end;
procedure TInputInt.SetData(var Rec);
var
R: LongInt absolute Rec;
begin
str(R, Data^);
SelectAll(true);
end;
function TInputInt.Valid(com: word): boolean;
var
r: LongInt;
i: integer;
v: boolean;
s1, s2: string;
begin
val(Data^, r, i);
if i <> 0 then
begin
MessageBox('Invalid input', nil, mfError + mfOkButton);
Valid := false;
exit;
end;
case int of
a_b: v := (r >= min) and (r <= max);
a_inf: v := (r >= min);
inf_b: v := (r <= max);
inf_inf: v := true;
end;
if not v then
begin
case int of
a_b:
begin
str(min: 11, s1);
s2 := s1 + ' <= I <= ';
str(max: 11, s1);
s2 := s2 + s1 + '! ';
end;
a_inf:
begin
str(min: 11, s1);
s2 := 'I >= ' + s1 + ' ! ';
end;
inf_b:
begin
str(max: 11, s1);
s2 := 'I <= ' + s1 + ' ! ';
end;
end;
MessageBox(s2, nil, mfError + mfOkButton);
end;
Valid := v;
end;
end.