Gilles MARCOU pisze:
Hello,

I'm trying to build an interface for a program so that it could be used
as a command line, a GUI or a CGI. For the CGI, I use powutils 1.7.1,
FPC 2.2.0 and Lazarus 0.9.24. I mean that the same executable should be
used either as a CGI, a command line or a GUI.

Currently I have kept separated in different unit each user interface
(see the code below). But, at execution, if there is an execution error,
it always open message box. Therefore, even in command line, the
software requires GUI libraries be there (GTK for instance) and it
simply does not work as a CGI.
You have to change all automatic initialization of visual components and make all linking with GUI libraries dynamic. That i no easy. But you can invoke second executable from this console (distribute 2 file, but always invoke the same)
Do you see a more clever solution? Otherwise, the only solution I see is
to keep all three interfaces in separate executable.

This is not problem to have separate executable, only have one source to both GUI. I made program which can work as desktop and as web-based (FCGI or standalone web server) Each form is create dynamical in runtime, source is one, but in compile time: 1 for desktop: clasic units from LCL (or rather VCL, on windows I use Delphi) 2.for web-base different set of units to handle web, but with the same API as VCL

Darek



Thanks in advance,
Gilles Marcou

program Predictor;

{$mode objfpc}{$H+}

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

type
    TRuntype=(CGI,CMD,GUI,UNK);

var
   cfg: TStringList;
   rt: TRuntype;
begin
  cfg:=TStringList.Create;
  cfg.LoadFromFile('cfg');
  rt:=UNK;
  if (cfg[0]='CGI') then
     rt:=CGI
  else if (cfg[0]='CMD') then
       rt:=CMD
  else if (cfg[0]='GUI') then
       rt:=GUI;
  FreeAndNil(cfg);
  if (rt=GUI) then
     RunGUI
  else if (rt=CMD) then
       RunCMD
  else if (rt=CGI) then
       RunCGI;
end.
-------
unit UnitRunGUI;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Interfaces, Forms, UnitPredictor;
procedure RunGUI;

implementation

procedure RunGUI;
begin
     Application.Initialize;
     Application.CreateForm(TFormPredictor, FormPredictor);
     Application.Run;
end;

end.
--------
unit UnitRunCGI;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, pwinit, pwmain;

procedure RunCGI;

implementation

procedure RunCGI;
begin
     outln('CGI: Not yet supported');
end;

end.
--------
unit UnitRunCMD;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils;
procedure RunCMD;

implementation

procedure RunCMD;
begin
     writeln('CMD: Not supported yet');
end;

end.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel



--
 Darek




_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to