-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCONNECT.PAS
221 lines (192 loc) · 6.34 KB
/
CONNECT.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
Unit Connect;
{$R+} {Range checking ON}
{
Form to set/reset rings that are logically disconnected
v01.01 2003-05-28 Original. Material from many sources.
v01.02 2003-05-29 First unit to use Template.
v01.03 2003-05-30 Remove Uses Buttons. Not needed.
v01.04 2003-06-13 OnCloseForm: added; calls OnClickButton (btnCancel)
v01.05 2003-06-13 MakeChildren: replace OnCloseClient by OnCloseForm
v01.06 2003-06-13 MakeChildren: remove OnDestroyClient
v01.07 2003-06-14 Hide the new btnRefresh inherited from TTemplate
}
INTERFACE
USES
{$IFDEF LINUX}
QForms, QGraphics, QStdCtrls,
{$ENDIF}
{$IFDEF MSWINDOWS}
Forms, Graphics, StdCtrls,
{$ENDIF}
SysUtils,
Template, Globals;
TYPE
TConnect = CLASS(TTemplate)
PROCEDURE OnCloseForm (Sender: TObject; VAR Action: TCloseAction);
PROCEDURE OnClickButton (Sender: TObject);
PRIVATE
{ Private declarations }
lblInstruct: TLabel;
cbRings: ARRAY [1..maxrings] OF TCheckBox;
PROCEDURE MakeChildren;
PROCEDURE Refresh;
PUBLIC
{ Public declarations }
END;
PROCEDURE StateSet (ring: INTEGER; state: BOOLEAN);
FUNCTION StateGet (ring: INTEGER): BOOLEAN;
FUNCTION DisconnectMsgGet (ring: INTEGER): String;
PROCEDURE Select;
IMPLEMENTATION
VAR connected: ARRAY [1..maxrings] OF BOOLEAN;
VAR frmConnect: TConnect;
{-------------------------------------------------------------}
PROCEDURE StateSet (ring: INTEGER; state: BOOLEAN);
BEGIN
connected[ring] := state;
END; {procedure 'StateSet'}
{-------------------------------------------------------------}
FUNCTION StateGet (ring: INTEGER): BOOLEAN;
BEGIN
StateGet := connected[ring];
END; {function 'StateGet'}
{-------------------------------------------------------------}
FUNCTION DisconnectMsgGet (ring: INTEGER): String;
BEGIN
IF (NOT connected[ring]) THEN DisconnectMsgGet := '!!! DISCONNECTED !!! ';
END; {function 'DisconnectMsgGet'}
{-------------------------------------------------------------}
PROCEDURE Select;
{Come here when this menu item selected on main form}
BEGIN
IF NOT Assigned (frmConnect) THEN BEGIN
frmConnect := TConnect.Create (Application);
frmConnect.MakeChildren;
END;
frmConnect.Show;
frmConnect.SetFocus;
frmConnect.WindowState := wsNormal;
frmConnect.Refresh;
END; {of procedure 'Select'}
{-------------------------------------------------------------}
PROCEDURE TConnect.Refresh;
{Refresh the check boxes and label colors}
VAR ring: INTEGER;
BEGIN
IF NOT Assigned (cbRings[1])
THEN
Application.MessageBox ('cbRings not assigned', 'Connect/Refresh', 0)
ELSE
FOR ring := 1 TO numrings DO WITH cbRings[ring] DO BEGIN
Checked := connected[ring];
IF Checked THEN Font.Color := clGreen
Else Font.Color := clRed;
END;
END; {of procedure 'Refresh'}
{-------------------------------------------------------------}
PROCEDURE TConnect.MakeChildren;
CONST nl = CHR(13) + CHR(10);
hex: ARRAY [0..$F] OF CHAR = ('0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F');
VAR ring: INTEGER;
BEGIN
{Form parameters}
With Self DO BEGIN
Caption := 'Logical connect/disconnect of rings';
Width := (Screen.Width * 4) DIV 5;
OnClose := OnCloseForm;
END;
{Instructions label}
lblInstruct := TLabel.Create (Self);
WITH lblInstruct DO BEGIN
Parent := Self;
Left := 20;
Top := 20;
Caption := 'Uncheck box and hit ' + nl +
'Apply or OK to ' + nl +
'logically disconnect' + nl +
'a ring. ' + nl + nl +
'Ring will not ' + nl +
'communicate with its' + nl +
'devices even if ' + nl +
'those devices are in' + nl +
'another physical ' + nl +
'ring. ' + nl + nl +
'Conversely, other ' + nl +
'rings may still try ' + nl +
'to communicate with ' + nl +
'devices in the ' + nl +
'disconnected ring! ';
END; {with}
{Command buttons}
WITH btnCancel DO BEGIN
Left := Self.Width - Width - 20;
Top := lblInstruct.Top;
OnClick := OnClickButton;
END;
WITH btnRefresh DO BEGIN
Visible := FALSE;
Enabled := FALSE;
END;
WITH btnApply DO BEGIN
Left := btnCancel.Left;
Top := btnCancel.Top + Height + (Height DIV 2);
OnClick := OnClickButton;
END;
WITH btnOK DO BEGIN
Left := btnCancel.Left;
Top := btnApply.Top + Height + (Height DIV 2);
OnClick := OnClickButton;
END;
WITH btnHelp DO BEGIN
Visible := FALSE;
Enabled := FALSE;
END;
{Dynamically create and fill the ring checkboxes}
FOR ring := 1 TO numrings DO
IF NOT Assigned (cbRings[ring]) THEN BEGIN
cbRings[ring] := TCheckBox.Create (Self);
WITH cbRings[ring] DO BEGIN
Parent := Self;
AllowGrayed := FALSE;
Left := lblInstruct.Left + lblInstruct.Width + 20;
Height := 20;
Top := lblInstruct.Top + (ring-1) * ((Height * 4) DIV 3);
Width := btnCancel.Left - Left - 20;
Caption := hex[ring] + ': ' +
'Ring ' + rlabel[ring] + ' ' + descriptor[ring];
END; {with}
END; {if}
IF (lblInstruct.Top + lblInstruct.Height) >
(cbRings[numrings].Top + cbRings[numrings].Height)
THEN Self.Height := lblInstruct.Top + lblInstruct.Height + 50
ELSE Self.Height := cbRings[numrings].Top + cbRings[1].Height + 50;
END; {of procedure MakeChildren}
{-------------------------------------------------------------}
PROCEDURE TConnect.OnCloseForm (Sender: TObject; VAR Action: TCloseAction);
BEGIN
OnClickButton (TObject(btnCancel));
END; {of procedure OnCloseForm}
{-------------------------------------------------------------}
PROCEDURE TConnect.OnClickButton (Sender: TObject);
VAR ring: INTEGER;
BEGIN
IF (Sender = btnApply) OR (Sender = btnOK) THEN BEGIN
{Latch check box values into working variables}
FOR ring := 1 TO numrings DO
connected[ring] := cbRings[ring].Checked;
Refresh;
END;
IF (Sender = btnOK) OR (Sender = btnCancel) THEN BEGIN
Self.Release;
frmConnect := NIL;
END;
END; {of procedure OnClickButton}
{-------------------------------------------------------------}
INITIALIZATION
BEGIN
END;
FINALIZATION
BEGIN
END;
{of unit Connect...} END.