Recent

Author Topic: How to get LAZARUS version within source code using compiler functions?  (Read 2468 times)

jamie

  • Hero Member
  • *****
  • Posts: 6091
as the title states, I need to obtain the version of Lazarus, not FPC in source code, is there any environment variables
Lazarus defines that can be queried via the {$IFDEF ….. } ?
The only true wisdom is knowing you know nothing

Wallaby

  • Jr. Member
  • **
  • Posts: 78
{$IF LCL_FULLVERSION>=1000000} //for laz 1.0.0.0 (major,minor,release,patch)
{$IF LCL_FULLVERSION>=1000200} //for laz 1.0.2.0

or check the LazVersion unit, which contains something like

const
  laz_major = 2;
  laz_minor = 0;
  laz_release = 1;
  laz_patch = 0;
  laz_fullversion = ((laz_major *  100 + laz_minor) * 100 + laz_release) * 100 + laz_patch;
  laz_version = '2.0.1.0';


jamie

  • Hero Member
  • *****
  • Posts: 6091
What I am looking for is a compiler define, one that has been set like this

{$DEFINE  Lazarus=1.8.4}

This would need to be global of course

The idea is the use compiler control to not compile in code or compile in different code depending on the
version I am running.

 The reason I want this is due to some issues existing in Lazarus now where it can be worked around but this
most likely will change later and then I could have it compile the proper code without making changes to the
source code.
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
It's not really the Lazarus version. After all, Lazarus is just an IDE, i.e. an overgrown text-editor. ;) What really matters is the version of the LCL and you can get that with LCL_FULLVERSION. For example:

Code: Pascal  [Select][+][-]
  1.   {$IF (LCL_FULLVERSION < 1080400)}
  2.   ShowMessage('I''ll use workarounds for Lazarus pre-1.8.4');
  3.   {$ELSE}
  4.   Showmessage('Woah! Congrats! Lazarus is at least 1.8.4.0!')
  5.   {$ENDIF}
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5448
  • Compiler Developer
What I am looking for is a compiler define, one that has been set like this

{$DEFINE  Lazarus=1.8.4}

This would need to be global of course
What Wallaby and lucamar posted is the correct approach. Though you need to add the LazVersion unit to your uses clause to be able to check for the constants using compiler directives (and it will only work after the whole uses clause is parsed).

jamie

  • Hero Member
  • *****
  • Posts: 6091
yes that is what I want. Thank you..
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018