TURBO PASCAL |
Новости
|
54: How do I test whether a file is already open in a TP program?A: This question is best answered by providing the code: uses Dos; {... for non-text files ...} function ISFOPEN (var filePointer : file) : boolean; begin isfopen := FileRec(filePointer).mode <> FmClosed; end; {} {... for text files ...} function ISTOPEN (var filePointer : text) : boolean; begin istopen := TextRec(filePointer).mode <> FmClosed; end; {} procedure TEST; { Testing a non-text file } const name = 'R:\TMP'; var f : file; begin Assign (f, name); writeln ('File ', name, ' is open is ', ISFOPEN(f)); {$I-} rewrite (f); {$I+} if IOResult <> 0 then begin writeln ('Failed to open ', name); exit; end; writeln ('File ', name, ' is open is ', ISFOPEN(f)); close(f); writeln ('File ', name, ' is open is ', ISFOPEN(f)); end; |
(с)Все права защищены По всем интересующим вопросам прошу писать на электронный адрес |