Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-05

writeln in win32 gui application

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

vs

Hi,

The following program gives run time error 103. If I uncomment the rewrite line, it runs ok. Is this a bug or feature? If it is a feature, can somebody explain, the reasoning behind it.

program guiwriteln;
{$mode objfpc}{$H+}
{$apptype gui}
begin
  //rewrite(output);
  writeln('Test');
end.

Regards,
Vincent.

Peter Vreman
to vs
you wrote 15 lines
Hi, The following program gives run time error 103. If I uncomment the rewrite line, it runs ok. Is this a bug or feature? If it is a feature, can somebody explain, the reasoning behind it. program guiwriteln; {$mode objfpc}{$H+} {$apptype gui} begin //rewrite(output); writeln('Test'); end.

When running in GUI mode the output and input files are not opened so there is no console window. With the rewrite(output) you explicitly open the output file and force the console window.

Peter

Michael Van Canneyt
to vs: The following program gives run time error 103. If I uncomment the rewrite line, it runs…
vs wrote 10 lines
Hi, The following program gives run time error 103. If I uncomment the rewrite line, it runs ok. Is this a bug or feature? If it is a feature, can somebody explain, the reasoning behind it. program guiwriteln; {$mode objfpc}{$H+} {$apptype gui}

This is the culprit. For GUI apps standard/input/output are not initialized. Initializing them would create a console window, which is not what you want when running a GUI application.

Michael.

Vincent Snijders
to Peter Vreman: When running in GUI mode the output and input files are not opened so there is no console…
Peter Vreman wrote 20 lines
At 11:55 9-5-2004, you wrote: >Hi, > >The following program gives run time error 103. If I uncomment the >rewrite line, it runs ok. Is this a bug or feature? If it is a feature, >can somebody explain, the reasoning behind it. > >program guiwriteln; > >{$mode objfpc}{$H+} >{$apptype gui} > >begin > //rewrite(output); > writeln('Test'); >end. When running in GUI mode the output and input files are not opened so there is no console window. With the rewrite(output) you explicitly open the output file and force the console window.

Well, that is the funny part. If I add the rewrite(output) the output file is opened (no crash and I can do writeln's), but no console window is opened either. Just the situation I want.

Now I want to know why it isn't opened by default. The drawback of opening it (the console window) doesn't happen. The output just seems to be ignored. (Good thing, because if you want to see the output, you should compile as a console application.)

Vincent.

Peter Vreman
to Vincent Snijders
Show quoted text 35 lines
On 9 May 2004 at 12:17, Peter Vreman wrote: > At 11:55 9-5-2004, you wrote: > >Hi, > > > >The following program gives run time error 103. If I uncomment the > >rewrite line, it runs ok. Is this a bug or feature? If it is a feature, > >can somebody explain, the reasoning behind it. > > > >program guiwriteln; > > > >{$mode objfpc}{$H+} > >{$apptype gui} > > > >begin > > //rewrite(output); > > writeln('Test'); > >end. > > When running in GUI mode the output and input files are not opened so > there > is no console window. With the rewrite(output) you explicitly open the > output file and force the console window. Well, that is the funny part. If I add the rewrite(output) the output file is opened (no crash and I can do writeln's), but no console window is opened either. Just the situation I want. Now I want to know why it isn't opened by default. The drawback of opening it (the console window) doesn't happen. The output just seems to be ignored. (Good thing, because if you want to see the output, you should compile as a console application.)

Compatibility with Delphi.

Matt Emson
to Peter Vreman
Compatibility with Delphi.

With Delphi, you only get a console window if you do one of two things (other than create one yourself, that is..)

1) You explicitly compile as a console app. *Any* GUI app can be compiled as a 'console app.. This is done through a command line switch, IDE option (project options) or by a compiler directive.
2) You spawn a subprocess that opens one and don't ask the console to be hidden.

I personally think the proplem is one of naming (Borlands fault) and that it should be "GUI with no standard I/O" and "Console/GUI with Console Window". There is of course a *third* mode I think is missing. This is the one most C/C++ apps have if you include stdio.h or iostream[.h]... That is a standard I/O mapped, no console opened. If you run *in* a console you see the output, but if you run via Explorer, you don't. Useful for debugging IMHO. From what I understand with this conversation, the rewrite creates this mode.... Hmmm useful ;-)

Matt