« 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:
const
lcl_version = // note: 48 = Ord('0')
{$ifdef ConditionalExpressions} {$if Declared(lcl_major) and (lcl_major >= 10)}
Chr (48+(lcl_major div 10)) + {$ifend} {$endif}
Chr (48+(lcl_major mod 10)) +'.'+
{$ifdef ConditionalExpressions} {$if Declared(lcl_minor) and (lcl_minor >= 10)}
Chr (48+(lcl_minor div 10)) + {$ifend} {$endif}
Chr (48+(lcl_minor mod 10)) +'.'+
{$ifdef ConditionalExpressions} {$if Declared(lcl_release) and (lcl_release >= 10)}
Chr (48+(lcl_release div 10)) + {$ifend} {$endif}
Chr (48+(lcl_release mod 10)) +'.'+
{$ifdef ConditionalExpressions} {$if Declared(lcl_patch) and (lcl_patch >= 10)}
Chr (48+(lcl_patch div 10)) + {$ifend} {$endif}
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:
00000000 -> 0.0.0.0 -> '0.0.0.0'
01060004 -> 1.6.0.4 -> '1.6.0.4'
01060200 -> 1.6.2.0 -> '1.6.2.0'
02309907 -> 2.30.99.7 -> '2.30.99.7'
99999999 -> 99.99.99.99 -> '99.99.99.99'
« Last Edit: November 18, 2016, 08:34:10 pm by Paulo França Lacerda (patulinu) »
Logged
Lazarus 1.6.0.4 on FreePascal 3.0
Windows 7 32-bit