[Lazarus] GUI frontend to a console application

Funky Beast funkybeast at pacific.net.sg
Wed Feb 25 06:04:44 CET 2009


Graeme Geldenhuys wrote:
> On Tue, Feb 24, 2009 at 3:08 PM, Martin Friebe <lazarus at mfriebe.de> wrote:
>> It will be similar (probably easier) if the command line app is *not*
>> interactive.
> 
> The console apps we want to wrap works similar to the SubVersion (svn)
> command line client. Execute with certain parameters and read back the
> results, which must be displayed in a GUI form via various components.
> 
> Some console apps which we will be writing ourselves will output %
> progress, which we would like to represent with a TProgressBar. The
> reason we want both console and a GUI wrapper is so that we can
> script/automate the console app, but also allow the user to run it
> manually via a easier to use GUI frontend.
> 
> 
> Regards,
>   - Graeme -
> 
> 
> _______________________________________________
> fpGUI - a cross-platform Free Pascal GUI toolkit
> http://opensoft.homeip.net/fpgui/
> _______________________________________________
> Lazarus mailing list
> Lazarus at lazarus.freepascal.org
> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
> 

If the console app is self-written, you can use a mix of TProcess and
TSimpleIPCServer and TSimpleIPCClient.

Add a TSimpleIPCClient to your console app, so that it can send message to its
paired up TSimpleIPCServer which is hosted on the GUI frontend. This way, your
console app can "speak" to your GUI frontend app. Be sure to read an argument
as your IPCServerName, so it knows which IPCServer to talk to.
On your GUI frontend, use a thread to read messages from the IPCServer continuously.

If you want to execute multiple console apps simultaneously, use TProcess to execute
your console apps with poWaiting and poUsePipes turned off (so that it returns control
to your app immediately) and use a TSimpleIPCServer to listen to the TSimpleIPCClient
from your console app.

In the long run you should have a multi-threaded process-manager that handles
a collection of TProcess and TSimpleIPCServer.

I have chopped up all my big apps into small console apps and frontends.
So, my apps can all run with or without a GUI. So my big app is now a
package of console apps and a frontend, sort of like how Linux works.

A rough model of my process-manager:
**********************************************************************************************
 TIPCServerThread = class (TThread)
 public
  IPCServer: TSimpleIPCServer;//For listening to the IPCClient of the console app
 end;

 TIPCProcess = class (TCollectionItem)
 public
  Process: TProcess;//For executing the console app (Execute without waiting)
  IPCServerThread: TIPCServerThread;//Listens and update status of this process

  property Status;
  property Progress;
  property MaxProgress;
  property Errors;

  //Note: the console app will receive an IPCServerName as a argument so it knows
  //      which IPCServer to talk to.
 end;

 TIPCProcessList = class (TCollection)//For handling a collection of TIPCProcess.

 TIPCProcessManager = class(TComponent)
  //For complex mangement of processes like executing events when a particular process completes.
  //or a timer for polling the processlist for status to be displayed or actions to be taken.
**********************************************************************************************

This allows me to add features to my app easier as debugging my new console app
is easier than debugging the monolithic app (most of my console apps handles
long-loopy functions).

Also you take advantage of multi-core processors instantly as the OS will do it for you
like as though you open multiple programs, you don't need to spend time tweaking your
threads to consume or force-feed them to a paticular core. The front end serves only to
display or execute console apps and load results.

my $0.002
Funky Beast



More information about the Lazarus mailing list