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

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

=== 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 suggestion:

=== example begin ===

program winerrortest;

{$apptype gui}

begin
  Writeln(StdErr, 'Hello World');
  Flush(StdErr);
  Writeln(StdOut, 'Hello World 2');
  Flush(StdOut);
end.

=== example end ===

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to