-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXITSEQ.PAS
227 lines (196 loc) · 6.11 KB
/
EXITSEQ.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
222
223
224
225
226
227
Unit ExitSeq;
{$R+} {Range checking ON}
{
Prompt user if FCP program exit has been requested
v01.01 2003-05-30 Original. Based on Connect.pas. Old exit_sequence code.
v01.02 2003-05-31 Replace crt32.Delay by TTimer.
v01.03 2003-06-13 Add OnCloseForm that calls OnClickButton btnCancel
v01.04 2003-06-13 Replace OnCloseClient, OnDestroyClient by OnCloseForm
v01.05 2003-06-14 Hide the new btnRefresh inherited from TTemplate
v02.00 2006-09-22 Add IMPLEMENTATION USES EventLog
OnClickButton: calls to AppEvLog 50002, 50003, 50004 added
}
INTERFACE
USES {also see IMPLEMENTATION USES}
{$IFDEF LINUX}
QForms, QExtCtrls, QStdCtrls,
{$ENDIF}
{$IFDEF MSWINDOWS}
Forms, ExtCtrls, StdCtrls,
{$ENDIF}
SysUtils,
Template;
TYPE
TExitSeq = CLASS(TTemplate)
PRIVATE
{ Private declarations }
lblInstruct: TLabel;
cbStage: TCheckBox;
FTimedOut: BOOLEAN;
tmTimeout: TTimer;
PROCEDURE OnTimerFire (Sender: TObject);
PROCEDURE OnCloseForm (Sender: TObject; VAR Action: TCloseAction);
PROCEDURE OnClickButton (Sender: TObject);
PROCEDURE MakeChildren;
PUBLIC
{ Public declarations }
END;
FUNCTION ShutMsgGet (ring: INTEGER): String;
PROCEDURE Select;
IMPLEMENTATION
USES {also see INTERFACE USES}
Globals, EventLog,
comp, comd;
VAR frmExitSeq: TExitSeq;
VAR shut: ARRAY [1..maxrings] OF BOOLEAN;
VAR ring: INTEGER;
{-------------------------------------------------------------}
FUNCTION ShutMsgGet (ring: INTEGER): String;
BEGIN
IF shut [ring] THEN ShutMsgGet := 'In shutdown ';
END; {function 'ShutMsgGet'}
{-------------------------------------------------------------}
PROCEDURE Select;
{Come here when this menu item selected on main form}
BEGIN
IF NOT Assigned (frmExitSeq) THEN BEGIN
frmExitSeq := TExitSeq.Create (Application);
frmExitSeq.MakeChildren;
END;
frmExitSeq.Show;
frmExitSeq.SetFocus;
frmExitSeq.WindowState := wsNormal;
END; {of procedure 'Select'}
{-------------------------------------------------------------}
PROCEDURE TExitSeq.MakeChildren;
CONST nl = CHR(13) + CHR(10);
BEGIN
{Form parameters}
WITH Self DO BEGIN
Caption := 'FCP program exit has been requested...';
Width := (Screen.Width * 4) DIV 5;
Height := (Screen.Height * 3) DIV 4;
Left := 0;
Top := Screen.Height - Height - 50;
OnClose := OnCloseForm;
END;
{Staged shutdown interval timer}
tmTimeout := TTimer.Create (Self);
WITH tmTimeout DO BEGIN
Enabled := FALSE;
Interval := 1000;
OnTimer := OnTimerFire;
END;
{Instructions label}
lblInstruct := TLabel.Create (Self);
WITH lblInstruct DO BEGIN
Parent := Self;
Left := 20;
Top := 20;
Caption := 'Check box for an orderly shutdown of ' + nl +
'devices in the field before stopping ' + nl +
'the control program. ' + nl + nl +
'If the box is unchecked, the program ' + nl +
'will exit immediately. Field devices ' + nl +
'will remain in their current state ' + nl +
'unless deactivated by watchdogs in the' + nl +
'field.';
END; {with}
{Command buttons inherited from TTemplate}
WITH btnCancel DO BEGIN
Left := lblInstruct.Left + lblInstruct.Width + 20;
Width := Self.Width - Left - 50;
Top := lblInstruct.Top;
Height := Self.Height - Top - 50;
OnClick := OnClickButton;
END;
WITH btnOK DO BEGIN {refashioned as the do shutdown button}
Caption := '&Shutdown FCP Program';
Default := FALSE;
Width := lblInstruct.Width;
Left := lblInstruct.Left;
Top := Self.Height - Height - 50;
OnClick := OnClickButton;
END;
WITH btnRefresh DO BEGIN
Visible := FALSE;
Enabled := FALSE;
END;
WITH btnApply DO BEGIN
Visible := FALSE;
Enabled := FALSE;
END;
WITH btnHelp DO BEGIN
Visible := FALSE;
Enabled := FALSE;
END;
{Fast/slow shutdown check box}
IF NOT Assigned (cbStage) THEN BEGIN
cbStage := TCheckBox.Create (Self);
WITH cbStage DO BEGIN
Parent := Self;
AllowGrayed := FALSE;
Left := lblInstruct.Left;
Height := 20;
Top := (lblInstruct.Top + lblInstruct.Height + btnOK.Top) DIV 2;
Width := lblInstruct.Width;
Caption := 'Staged shutdown of field devices';
Checked := TRUE;
END; {with}
END; {if}
END; {of procedure MakeChildren}
{-------------------------------------------------------------}
PROCEDURE TExitSeq.OnTimerFire (Sender: TObject);
BEGIN
tmTimeout.Enabled := FALSE;
FTimedOut := TRUE;
END; {of procedure OnTimerFire}
{-------------------------------------------------------------}
PROCEDURE TExitSeq.OnCloseForm (Sender: TObject; VAR Action: TCloseAction);
BEGIN
OnClickButton (TObject(btnCancel));
END; {of procedure OnCloseForm}
{-------------------------------------------------------------}
PROCEDURE TExitSeq.OnClickButton (Sender: TObject);
VAR ring, count: INTEGER;
BEGIN
{DebugLogFileClose and reldisc not done by this version}
IF (Sender = btnOK) THEN BEGIN
IF cbStage.Checked THEN BEGIN
EventLog.AppEvLog (50002);
btnCancel.Caption := '&Abort';
FOR ring := 1 TO numrings DO BEGIN
oper[ring] := FALSE;
shut[ring] := TRUE;
FOR count := 5 DOWNTO 1 DO BEGIN
lblInstruct.Caption :=
'Shutting off ring ' + rlabel[ring] + ': ' + IntToStr(count);
tmTimeout.Enabled := TRUE;
FTimedOut := FALSE;
REPEAT tinter; Application.ProcessMessages; UNTIL FTimedOut;
END;
END;
END;
EventLog.AppEvLog (50004);
System.Halt;
END;
IF (Sender = btnCancel) THEN BEGIN
EventLog.AppEvLog (50003);
tmTimeout.Enabled := FALSE;
FOR ring := 1 TO numrings DO BEGIN
oper[ring] := TRUE;
shut[ring] := FALSE;
END;
Self.Release;
frmExitSeq := NIL;
END;
END; {of procedure OnClickButton}
{-------------------------------------------------------------}
INITIALIZATION
BEGIN
FOR ring := 1 TO maxrings DO shut[ring] := FALSE;
END;
FINALIZATION
BEGIN
END;
{of unit ExitSeq...} END.