[fpc-devel] Re: CGI/Command line/GUI all in one

Gilles MARCOU g.marcou at chimie.u-strasbg.fr
Thu Sep 17 15:41:05 CEST 2009


Hi,

thank you for your very fast answers.

Joost, I had an application that worked as GUI (my boss likes GUI), then
my colleagues asked me for a command line and my boss asked for a CGI...
I resulted in 3 separate projects which is impossible to maintain -I'm
not well enough organized. So I wanted to fuse all projects in one
application which, according to a config file would run as a CGI,
console application or GUI.

So, yes, if the application is console only, there is no problem. But it
should, idealy, be running also as  GUI. However, I did not understood
what is the 'nogui' widgetset and how can I use it? It sounds promising!
I think it is in alpha release in Lazarus 0.9.26, that's it?

Michael, the widgetset I'm using is GTK usually. I am using my computer
with a local installation of Apache to test my CGI; in that case, the
widgetset is obviously compatible. On the webserver, I recompiled from
scratch, but it does not work neither. In both cases, I got an "Internal
Server Error" message from Apache. In the log of Apache, I found that
the CGI ended prematurely because GTK could open display.

I believe Graeme is right. As long as I do not trigger any GUI unit, the
CGI works fine. Using the suggestion of Graeme, I ended up with a
solution at compile time. I enclose in the main program three user
interfaces with $DEFINE and I select the needed one with the option
-d<x> of the compiler. Using the same units as in my previous post, I
can fuse all my projets compiling the code with option -dGUImode for a
GUI application, -dCMDmode for console application, -dCGImode for CGI
application -see the code at the end of the post.

Yet it is not as satisfactory as deciding at compile time rather than
deciding at run time. I'm open to all suggestions.

Thanks for your help,
Gilles Marcou

program Predictor;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  //{ you can add units after this },
  Classes, sysutils,
  {$IFDEF GUImode}UnitRunGUI;{$ENDIF}
  {$IFDEF CMDmode}UnitRunCMD;{$ENDIF}
  {$IFDEF CGImode}UnitRunCGI;{$ENDIF}

begin
  {$IFDEF GUImode}RunGUI;{$ENDIF}
  {$IFDEF CMDmode}RunCMD;{$ENDIF}
  {$IFDEF CGImode}RunCGI;{$ENDIF}
end.






More information about the fpc-devel mailing list