[fpc-pascal] how to test if a file is open to write?
Ludo Brands
ludo.brands at free.fr
Thu Jul 14 09:20:55 CEST 2011
What about using IsConsole? This indicates if the app has been compiled with
{$apptype console}.
Your solution has the advantage of being simple and cross-platform.
On windows this works for me:
function IsConsoleOpen:boolean;
var mode:longword;
begin
result:=GetConsolemode(GetStdHandle(STD_OUTPUT_HANDLE),mode);
end;
Ludo
> -----Message d'origine-----
> De : fpc-pascal-bounces at lists.freepascal.org
> [mailto:fpc-pascal-bounces at lists.freepascal.org] De la part de Bernd
> Envoyé : mercredi 13 juillet 2011 21:06
> À : FPC-Pascal users discussions
> Objet : [fpc-pascal] how to test if a file is open to write?
>
>
> 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.
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list