[Lazarus] Startup environment: to Gui, or not to GUI?

Henry Vermaak henry.vermaak at gmail.com
Tue Apr 11 17:50:43 CEST 2017


On Tue, Apr 11, 2017 at 01:34:35PM +0000, Mark Morgan Lloyd via Lazarus wrote:
> Something like this does appear to work, tested on Linux only.
> 
> function notGui(): boolean;
> 
> var     i: integer;
> 
> begin
>   i := IsaTty(Input);
> {$ifdef ISGUI }
>   exit false;
> {$endif ISGUI }
> {$ifdef NOGUI }
>   exit true;
> {$endif NOGUI }
>   result := i <> 0
> end { notGui } ;
> 
> The explicit overrides might be needed during debugging, since the
> involvement of gdb forces the program to think it's being run from a shell
> session.

I'd recommend making the overrides command line parameters.  That way
you do away with the ifdefs and a user can always override it if your
logic somehow doesn't do the right thing.

> Looking back through older sources, I've had to jump through hoops-
> reopening the input and using GetFileType() under Windows- to find out
> whether stdin was piped. Fortunately I don't need that here.

The experience on Windows is pretty awful and I've seen some interesting
tricks to get a program to do the right thing based on where it was
launched from.  For example, Visual Studio's devenv.com vs. devenv.exe,
using the fact that .com takes preference over .exe in the terminal to
handle the command line parameters and sending output to the terminal
that it was called from.

Henry


More information about the Lazarus mailing list