Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-04

Linux GUI Application define CONSOLE

10 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Daniel Simoes de Ameida

Hello All,

I noticed that GUI Applications on Linux (gtk2) are always signed as CONSOLE apptype by default...

For instance, the code below generate a compiler Error on Linux, but works on Windows

Please see these images for a better comprehension http://imagebin.org/253733

http://imagebin.org/253734

unit Unit1;
{$mode objfpc}{$H+}
interface
uses
? Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
{$IFDEF CONSOLE}
? ERROR?? // <-- unit1.pas(11,3) Fatal: Syntax error, "IMPLEMENTATION" expected but "identifier ERROR" found
{$ENDIF}

type
? TForm1 = class(TForm)
? private
??? { private declarations }
? public
??? { public declarations }
? end;
......

I am using Lazarus 1.1 from SVN (rev 40699M)

and FPC 2.7.1 also from SVN? Free Pascal Compiler version 2.7.1 [2013/04/02] for i386

Is there any extra configuration needed to be done on Project Options ?

?
[]s Daniel

Conhe?a o Projeto ACBr - Automa?ao Comercial Brasil DJSystem a Loja Patrocinadora do ACBr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130412/38322dba/attachment.html>

Reply by email

Daniel Simoes de Ameida
to Mattias Gaertner

Hi Mattias,

Thanks for answering...

I?m confusing... I always find out that the "CONSOLE" directive exists only for applications that does not require a GUI.... or in other words, applications that does not require a X server

How can I distinguish applications in Text mode (CONSOLE) from Graphics Applications (GUI) ??

?
[]s Daniel

Conhe?a o Projeto ACBr - Automa?ao Comercial Brasil DJSystem a Loja Patrocinadora do ACBr

Show quoted text 28 lines
________________________________ De: Mattias Gaertner Para: Enviadas: Sexta-feira, 12 de Abril de 2013 12:12 Assunto: Re: [Lazarus] Linux GUI Application define CONSOLE On Fri, 12 Apr 2013 08:01:14 -0700 (PDT) Daniel Simoes de Ameida wrote: > Hello All, > > I noticed that GUI Applications on Linux (gtk2) are always signed as CONSOLE apptype by default... Yes, Linux GUI Applications have always a console. Windows GUI Applications do not have a console. Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130413/73590332/attachment-0001.html>

Reply by email

leledumbo
to Daniel Simoes de Ameida
I?m confusing... I always find out that the "CONSOLE" directive exists only

for applications that does not require a GUI.... or in other words, applications that does not require a X server

Linux applications are console, Linux doesn't have integrated GUI as a part of the system like Windows (which is why replacing X server with something else is quite easily possible). Everything (including X server) runs on top of it. It's just a matter of showing the console or not. Launching Lazarus from terminal will show output log during its execution without the need to redirect to file via --debug-log option, which is mandatory on Windows.

How can I distinguish applications in Text mode (CONSOLE) from Graphics Applications (GUI) ?

I don't think it's possible on Linux. Do you have any need for that?

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Linux-GUI-Application-define-CONSOLE-tp4030537p4030548.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

Sven Barth
to Daniel Simoes de Ameida: Thanks for answering... I?m confusing... I always find out that the "CONSOLE" directive…
Daniel Simoes de Ameida wrote 6 lines
I?m confusing... I always find out that the "CONSOLE" directive exists only for applications that does not require a GUI.... or in other words, applications that does not require a X server How can I distinguish applications in Text mode (CONSOLE) from Graphics Applications (GUI) ?

You can't as leledumbo wrote already. The compiler will even warn if you use "$apptype ..." in the main program file on Unix systems, because it is simply not supported there.

As a sidenote: checking for "ifdef console" or "ifdef gui" is problematic, because you will only be aware of a change if your units are completely recompiled. If you change the setting (e.g. by not using the IDE dialogs, but by manually adding "apptype console" to your program file) the compiler will only recompile the main program unit and your units won't detect a change.

Regards,
Sven

Reply by email

Daniel Simoes de Ameida
to leledumbo: for applications that does not require a GUI.... or in other words, applications that…

Hi Leledumbo,

Thanks for the explanation... I agree with this point of view...

I have some code shared between 2 applications, running on Text mode and GUI... And I used CONSOLE directive to distinguish some specific code for GUI application... I can fix my code, using another compiler directive on Build modes... I was considering CONSOLE directive was equal on Linux and Windows... ?
[]s Daniel

Conhe?a o Projeto ACBr - Automa?ao Comercial Brasil DJSystem a Loja Patrocinadora do ACBr

Show quoted text 37 lines
________________________________ De: leledumbo Para: Enviadas: S?bado, 13 de Abril de 2013 14:35 Assunto: Re: [Lazarus] Linux GUI Application define CONSOLE > I?m confusing... I always find out that the "CONSOLE" directive exists only for applications that does not require a GUI.... or in other words, applications that does not require a X server Linux applications are console, Linux doesn't have integrated GUI as a part of the system like Windows (which is why replacing X server with something else is quite easily possible). Everything (including X server) runs on top of it. It's just a matter of showing the console or not. Launching Lazarus from terminal will show output log during its execution without the need to redirect to file via --debug-log option, which is mandatory on Windows. > How can I distinguish applications in Text mode (CONSOLE) from Graphics > Applications (GUI) ? I don't think it's possible on Linux. Do you have any need for that? -- View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Linux-GUI-Application-define-CONSOLE-tp4030537p4030548.html Sent from the Free Pascal - Lazarus mailing list . -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130414/95a6ba61/attachment-0001.html>

Reply by email

Daniel Simoes de Ameida
to Sven Barth: You can't as leledumbo wrote already. The compiler will even warn if you use "$apptype…

?
[]s Daniel

Conhe?a o Projeto ACBr - Automa?ao Comercial Brasil DJSystem a Loja Patrocinadora do ACBr

Show quoted text 36 lines
________________________________ De: Sven Barth Para: Enviadas: S?bado, 13 de Abril de 2013 18:49 Assunto: Re: [Lazarus] Linux GUI Application define CONSOLE On 13.04.2013 18:48, Daniel Simoes de Ameida wrote: > I?m confusing... I always find out that the "CONSOLE" directive exists > only for applications that does not require a GUI.... or in other words, > applications that does not require a X server > > How can I distinguish applications in Text mode (CONSOLE) from Graphics > Applications (GUI) ? You can't as leledumbo wrote already. The compiler will even warn if you use "$apptype ..." in the main program file on Unix systems, because it is simply not supported there. As a sidenote: checking for "ifdef console" or "ifdef gui" is problematic, because you will only be aware of a change if your units are completely recompiled. If you change the setting (e.g. by not using the IDE dialogs, but by manually adding "apptype console" to your program file) the compiler will only recompile the main program unit and your units won't detect a change. Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130414/3248da94/attachment.html>

Reply by email

Daniel Simoes de Ameida
to Sven Barth: You can't as leledumbo wrote already. The compiler will even warn if you use "$apptype…

Sorry for previous message...

I really hate Yahoo Mail, I cant find a way to avoid top posting...

I found a way to share code between GUI and CONSOLE applications... On CONSOLE applications, I do not use Packages dependencies, instead I add all directories from required Packages on "Other Unit Files", but I also inform a "Unit Output directory", so all files are always recompiled, as CONSOLE mode, and .PPU saved on a different location...

?
[]s Daniel

Conhe?a o Projeto ACBr - Automa?ao Comercial Brasil DJSystem a Loja Patrocinadora do ACBr

Show quoted text 36 lines
________________________________ De: Sven Barth Para: Enviadas: S?bado, 13 de Abril de 2013 18:49 Assunto: Re: [Lazarus] Linux GUI Application define CONSOLE On 13.04.2013 18:48, Daniel Simoes de Ameida wrote: > I?m confusing... I always find out that the "CONSOLE" directive exists > only for applications that does not require a GUI.... or in other words, > applications that does not require a X server > > How can I distinguish applications in Text mode (CONSOLE) from Graphics > Applications (GUI) ? You can't as leledumbo wrote already. The compiler will even warn if you use "$apptype ..." in the main program file on Unix systems, because it is simply not supported there. As a sidenote: checking for "ifdef console" or "ifdef gui" is problematic, because you will only be aware of a change if your units are completely recompiled. If you change the setting (e.g. by not using the IDE dialogs, but by manually adding "apptype console" to your program file) the compiler will only recompile the main program unit and your units won't detect a change. Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130414/e84310e7/attachment.html>

Reply by email

leledumbo
to Daniel Simoes de Ameida

If your design is modular enough, you can use frontend-backend architecture. Only the frontend should differ. This could be achieved by having 2 .lpi referencing the same backend unit, with each own frontend (user interface).

Another way would be to use build mode, differing in -Fu paths. One will refer to the console unit, while the other to the gui. This way requires you to have both units having the same interface. To ease maintenance, you could instead make one unit, but the implementation part is just an {$include} directive. This time, -Fi (instead of -Fu) will decide the path where the include file should be searched. So the layout is like:

Solution 1 (-Fu):
-backend.pas
-frontend/
--console/
---frontend.pas
--gui/
---frontend.pas

Solution 2 (-Fi):
-backend.pas
-frontend.pas
-include/
--console/
---frontend.inc
--gui/
---frontend.inc

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Linux-GUI-Application-define-CONSOLE-tp4030537p4030599.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

Kostas Michalopoulos
to leledumbo

As a side note, in order to figure out if your program is running under X11 in Linux you can simply check for the DISPLAY environment variable:

program test;
uses
  SysUtils;
begin
  if GetEnvironmentVariable('DISPLAY')  '' then
    Writeln('Hello X11')
  else
    Writeln('Hello Console');
end.

Obviously the program will detect X11 even if it is running under a terminal emulator like xterm, konsole, gnome-terminal, etc.

This way you can detect if the user tries to run the program from a pure console (like a virtual terminal from Ctrl+Alt+F1 to F6 in most Linux machines or from a remote connection via SSH) or from under X11 and use the appropriate user interface at launch time.

leledumbo wrote 45 lines
If your design is modular enough, you can use frontend-backend architecture. Only the frontend should differ. This could be achieved by having 2 .lpi referencing the same backend unit, with each own frontend (user interface). Another way would be to use build mode, differing in -Fu paths. One will refer to the console unit, while the other to the gui. This way requires you to have both units having the same interface. To ease maintenance, you could instead make one unit, but the implementation part is just an {$include} directive. This time, -Fi (instead of -Fu) will decide the path where the include file should be searched. So the layout is like: Solution 1 (-Fu): -backend.pas -frontend/ --console/ ---frontend.pas --gui/ ---frontend.pas Solution 2 (-Fi): -backend.pas -frontend.pas -include/ --console/ ---frontend.inc --gui/ ---frontend.inc -- View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Linux-GUI-Application-define-CONSOLE-tp4030537p4030599.html Sent from the Free Pascal - Lazarus mailing list . -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130414/62e949ea/attachment.html>

Reply by email