{ Simple program that demonstrates the TFileRec structure }
{ Written by Valery Votintsev <rswag@sources.ru> }
program test;
uses dos,strings;
Const
{ File State Bit Values}
file_readable = 1;
file_writeable = 2;
file_opened = 4;
file_assigned = 8;
file_eof = 16;
file_text = 32;
file_file = 64;
file_fileof = 128;
file_tty = 256;
file_special = 512;
file_settextbuf= 1024;
{ File State Bit Names}
StatusString: Array[1..11] of string = (
'file_readable',
'file_writeable',
'file_opened',
'file_assigned',
'file_eof',
'file_text',
'file_file',
'file_fileof',
'file_tty',
'file_special',
'file_settextbuf'
);
var
handle: integer; { File Handle }
F: file; { File Variable }
fname:string; { File Name }
Ft: tFileRec absolute F; { TFileRec Structure }
procedure WriteFileStatus;
var
i, { Counter }
bit: integer; { State Bit Value }
fstate:word; { File State Value }
begin
fstate := word(Ft.state); { Get the File State }
writeln(' Ft.name: ',Ft.name); { Write the Filename }
writeln(' Ft.handle: ',Ft.handle); { Write the Handler # }
writeln(' Ft.rec_len: ',Ft.rec_len); { Write the Record Length }
writeln(' Ft.state: ',hex(Fstate),':');{ Write the File State }
bit := 1;
for i:=1 to 11 do begin
if (fstate and bit) = bit then { Write the Flag if setted }
writeln(' bit ',i:2,' (',bit,') - ',StatusString[i]);
bit := bit shl 1; { Next Bit Value }
end;
writeln;
end;
begin
assign(F,'test.tst');
writeln('Step 1. File "test.tst" assigned.');
writeFileStatus; { Write the File Status }
write('Press <Enter> for continue: ');
readln; { Wait for Enter }
rewrite(F);
writeln('Step 2. File "test.tst" opened.');
writeFileStatus; { Write the File Status }
write('Press <Enter> for continue: ');
readln; { Wait for Enter }
close(F);
writeln('Step 3. File "test.tst" closed.');
writeFileStatus; { Write the File Status }
write('Press <Enter> for quit: ');
readln; { Wait for Enter }
end.