This repository was archived by the owner on Oct 11, 2022. It is now read-only.
forked from nickelsworth/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0039.pas
More file actions
87 lines (73 loc) · 2.58 KB
/
Copy path0039.pas
File metadata and controls
87 lines (73 loc) · 2.58 KB
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
{
From: GUY MCLOUGHLIN
Subj: Checking file open
I'm looking for a way of detecting if a file is currently open,
so my ExitProc can close it when open and not fail when trying
to close a file that is not open.
(* Public-domain demo to check a file variable's *)
(* current file mode. Guy McLoughlin - Oct '93. *)
}
program Test_FileMode_Demo;
uses
dos;
(**** Display current filemode for a file variable. *)
(* *)
procedure DisplayFileMode({input } const fi_IN);
begin
case textrec(fi_IN).mode of
FMclosed : writeln('* File closed');
FMinput : writeln('* File open in read-only mode');
FMoutput : writeln('* File open in write-only mode');
FMinout : writeln('* File open in read/write mode')
else
writeln('* File not assigned')
end
end; (* DisplayFileMode. *)
(**** Check for IO file errors. *)
(* *)
procedure CheckForIOerror;
var
in_Error : integer;
begin
in_Error := ioresult;
if (ioresult <> 0) then
begin
writeln('Error creating file');
halt(1)
end
end; (* CheckForIOerror. *)
var
fi_Temp1 : text;
fi_Temp2 : file;
BEGIN
(* Demo filemodes for a TEXT file variable. *)
writeln('TEXT file variable test');
DisplayFileMode(fi_Temp1);
assign(fi_Temp1, 'TEST.DAT');
DisplayFileMode(fi_Temp1);
{$I-} rewrite(fi_Temp1); {$I+}
CheckForIOerror;
DisplayFileMode(fi_Temp1);
{$I-} close(fi_Temp1); {$I+}
CheckForIOerror;
DisplayFileMode(fi_Temp1);
(* Demo filemodes for an UNTYPED file variable. *)
writeln;
writeln('UNTYPED file variable test');
DisplayFileMode(fi_Temp2);
assign(fi_Temp2, 'TEST.DAT');
DisplayFileMode(fi_Temp2);
{$I-} rewrite(fi_Temp2); {$I+}
CheckForIOerror;
DisplayFileMode(fi_Temp2);
{$I-} close(fi_Temp2); {$I+}
CheckForIOerror;
DisplayFileMode(fi_Temp2)
END.
*** NOTE: If you are not using version 7 of Turbo Pascal, change
the input parameter of the DisplayFileMode routine from
a CONSTANT parameter to a VAR parameter.
ie: TP7+ : DisplayFileMode({input } const fi_IN);
TP4+ : DisplayFileMode({input } var fi_IN);
- Guy