[fpc-pascal] how to test if a file is open to write?

Bernd prof7bit at googlemail.com
Wed Jul 13 21:06:22 CEST 2011


Because I have no idea how to do this properly (It has been a hundred
years since I last used this form of file IO in Pascal) I have done
the following hack, just to get it running somehow but now I wonder
what would be the proper way to do this. How can I do something like a
hypothetical IsOpen(StdOut) the proper way? This is what I have done
but I don't like it:

implementation
var
  HasOutput: Boolean = True;

procedure log(const s: String);
begin
  if HasOutput then
    writeln(s);
end;

initialization
  try
    writeln();
  except
    HasOutput := False;
  end;
end.



More information about the fpc-pascal mailing list