Recent

Author Topic: lcl_version as constant expression  (Read 2127 times)

Paulo França Lacerda

  • New Member
  • *
  • Posts: 44
    • BlaisePoint Informática
lcl_version as constant expression
« on: November 17, 2016, 09:23:48 pm »
I was looking at the LclVersion unit sources and found interesting the way the value of lcl_fullversion is set, by constant expression. I then started using the same scheme for my projects.

However, the
value of  lcl_version is hardcoded (eg: '1.6.0.4'). I wondered: Doesn't it deserve a constant expression as well? So I did this (to my programs), then adjusted it for the LCL case:

Code: Pascal  [Select][+][-]
  1. const
  2.   lcl_version =  // note: 48 = Ord('0')
  3.     {$ifdef ConditionalExpressions} {$if Declared(lcl_major) and (lcl_major >= 10)}
  4.      Chr (48+(lcl_major div 10)) + {$ifend} {$endif}
  5.      Chr (48+(lcl_major mod 10)) +'.'+
  6.  
  7.     {$ifdef ConditionalExpressions} {$if Declared(lcl_minor) and (lcl_minor >= 10)}
  8.      Chr (48+(lcl_minor div 10)) + {$ifend} {$endif}
  9.      Chr (48+(lcl_minor mod 10)) +'.'+
  10.  
  11.     {$ifdef ConditionalExpressions} {$if Declared(lcl_release) and (lcl_release >= 10)}
  12.      Chr (48+(lcl_release div 10)) + {$ifend} {$endif}
  13.      Chr (48+(lcl_release mod 10)) +'.'+
  14.  
  15.     {$ifdef ConditionalExpressions} {$if Declared(lcl_patch) and (lcl_patch >= 10)}
  16.      Chr (48+(lcl_patch div 10)) + {$ifend} {$endif}
  17.      Chr (48+(lcl_patch mod 10));

This code supports versions from 0.0.0.0 to 99.99.99.99 (more than enough), having that only the significant digits will appear in the resulting string.
For instance:
Code: Pascal  [Select][+][-]
  1. 00000000 -> 0.0.0.0 -> '0.0.0.0'
  2. 01060004 -> 1.6.0.4 -> '1.6.0.4'
  3. 01060200 -> 1.6.2.0 -> '1.6.2.0'
  4. 02309907 -> 2.30.99.7 -> '2.30.99.7'
  5. 99999999 -> 99.99.99.99 -> '99.99.99.99'
« Last Edit: November 18, 2016, 08:34:10 pm by Paulo França Lacerda (patulinu) »
Lazarus 1.6.0.4 on FreePascal 3.0
Windows 7 32-bit

 

TinyPortal © 2005-2018