[fpc-pascal] Program without window but messages

Sven Barth pascaldragon at googlemail.com
Wed Apr 25 19:16:51 CEST 2012

On 24.04.2012 18:25, J├╝rgen Hestermann wrote:
> I wanted to write a program that has no window but may show messages to
> the user.
> I have lots of such programs written with Virtual Pascal but I am
> struggling
> to do the same with Free Pascal/Lazarus.
> A simple test program would look like this:
> --------------------------------
> program Test;
> {$mode objfpc}{$H+}
> uses Interfaces,Forms,Windows,SysUtils,Dialogs;
> {$R *.res}
> begin
> ShowMessage('TEST');
> end.
> --------------------------------

A different (maybe not completly serious ;) ) idea is the following: If 
you only want to show error messages and your application should only 
work on Windows then you can do the following:

=== example begin ===

program Test;

{$apptype gui} // only to illustrate that this is a GUI application

   Writeln(StdErr, 'TEST'); // alternatively you can use StdOut as well

=== example end ===

This way an error dialog that is created using basic Windows API calls 
is created which you can confirm using Ok. This only works on Windows 
and only if the application is compiled as a GUI application (which is 
by default the case in Lazarus). There is only one caveat: The dialog is 
not immediately displayed, but only if enough data has accumulated and 
Flush(StdErr) doesn't work either in that case to force the output... 
thus the following code will show one dialog which contains both written 
lines (as seperate lines) - that's why this idea isn't a really serious 

=== example begin ===

program winerrortest;

{$apptype gui}

   Writeln(StdErr, 'Hello World');
   Writeln(StdOut, 'Hello World 2');

=== example end ===


More information about the fpc-pascal mailing list