Recent

Author Topic: [SOLVED] GUI type detection  (Read 584 times)

Raul_ES

  • Full Member
  • ***
  • Posts: 138
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
[SOLVED] GUI type detection
« on: March 12, 2020, 02:44:04 am »
Hi,


do you know how can I make my program detect the GUI library is being used? I mean that I need to detect if it is GTK2 , QT4, QT5, version of the QT compilation...those things.

The following doesn't work
Code: Pascal  [Select][+][-]
  1.  
  2. {$ifdef lclgtk}
  3.   _GUI_ := 'GTK';
  4. {$endif}


thanks
« Last Edit: March 13, 2020, 06:08:55 pm by Raul_ES »
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

eljo

  • Sr. Member
  • ****
  • Posts: 358
Re: GUI type detection
« Reply #1 on: March 12, 2020, 03:37:01 am »
works for me
Code: Pascal  [Select][+][-]
  1. function GetGUITarget:string;
  2. begin
  3. {$IFDEF LCLGTK}
  4.   result := 'GTK';
  5. {$ENDIF}
  6. {$IFDEF LCLGTK2}
  7.   result := 'GTK2';
  8. {$ENDIF}
  9. {$IFDEF LCLWIN32}
  10.   result := 'Win32';
  11. {$ENDIF}
  12. {$IFDEF LCLQT}
  13.   result := 'QT';
  14. {$ENDIF}
  15. end;            
  16.  

lucamar

  • Hero Member
  • *****
  • Posts: 2849
Re: GUI type detection
« Reply #2 on: March 12, 2020, 01:22:46 pm »
For completeness sake, if you ever want to get that info at run time, you can use the constants in uniit LCLPlatformDef. This function, for example, returns a string with the Lazarus version (taken from unit LazVersion) and widgetset for, say, an "about box":

Code: Pascal  [Select][+][-]
  1. uses
  2.   LCLPlatformDef, LazVersion;
  3.  
  4. const
  5.   sLazVers = '%d.%d.%d (%s)'; {version (widgetset)}
  6.  
  7. function LazarusInfo: String;
  8. var
  9.   platform: String;
  10. begin
  11.   platform := LCLPlatformDisplayNames[GetBuildLCLWidgetType];
  12.   Result := Format(sLazVers,
  13.                    [laz_major, laz_minor, laz_release, platform]);
  14. end;

Note, though, that GetBuildLCLWidgetType() will tell you the widgetset for which Lazarus itself was built which, while also  the default it uses to build your apps, might not coincide if, for example, you're cross-compiling to some other target.
« Last Edit: March 12, 2020, 01:41:19 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Raul_ES

  • Full Member
  • ***
  • Posts: 138
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: GUI type detection
« Reply #3 on: March 13, 2020, 06:08:37 pm »
Thanks, that's exactly what I need


regards,
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

Zoran

  • Hero Member
  • *****
  • Posts: 1558
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: GUI type detection
« Reply #4 on: March 13, 2020, 07:35:50 pm »
Note, though, that GetBuildLCLWidgetType() will tell you the widgetset for which Lazarus itself was built which, while also  the default it uses to build your apps, might not coincide if, for example, you're cross-compiling to some other target.

Yes. Therefore, instead of GetBuildLCLWidgetType(), better use GetDefaultLCLWidgetType() from unit InterfaceBase.

lucamar

  • Hero Member
  • *****
  • Posts: 2849
Re: GUI type detection
« Reply #5 on: March 13, 2020, 08:59:05 pm »
Yes. Therefore, instead of GetBuildLCLWidgetType(), better use GetDefaultLCLWidgetType() from unit InterfaceBase.

Good catch. I (mistakenly) thought it just read LCLPlatformDef.BuildLCLWidgetType but it appears it (and the complementary GetLCLWidgetTypeName()) reads the current widgetset if any and uses BuildLCLWidgetType only as fallback.

Thanks, Zoran. Never go to bed without learning something new, they say :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Zoran

  • Hero Member
  • *****
  • Posts: 1558
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: GUI type detection
« Reply #6 on: March 13, 2020, 11:03:04 pm »
Yes. Therefore, instead of GetBuildLCLWidgetType(), better use GetDefaultLCLWidgetType() from unit InterfaceBase.

Good catch. I (mistakenly) thought it just read LCLPlatformDef.BuildLCLWidgetType but it appears it (and the complementary GetLCLWidgetTypeName()) reads the current widgetset if any and uses BuildLCLWidgetType only as fallback.

Thanks, Zoran. Never go to bed without learning something new, they say :D

You are welcome.
I'm not surprised by your mistake, I think the name of this function is confusing actually -- GetDefaultLCLWidgetType -- better name would be GetCurrentLCLWidgetType, or simply (perhaps the best) GetWidgetType.

 

TinyPortal © 2005-2018