Recent

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

jamie

  • Hero Member
  • *****
  • Posts: 2140
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 ….. } ?
Number 1 at blue screen app creations!

Wallaby

  • New Member
  • *
  • Posts: 22
{$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: 2140
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.
Number 1 at blue screen app creations!

lucamar

  • Hero Member
  • *****
  • Posts: 2120
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 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

PascalDragon

  • Hero Member
  • *****
  • Posts: 700
  • 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: 2140
yes that is what I want. Thank you..
Number 1 at blue screen app creations!