Recent

Author Topic: Adding new version no when compiling  (Read 1028 times)

ronhud

  • Jr. Member
  • **
  • Posts: 55
Adding new version no when compiling
« on: September 18, 2020, 10:37:20 am »
I would like to display a version no on my main form which only changes when the program is compiled.  I read about compile time macros - would this be the way to do it?   Some code in the program to display an incremented number that is only actuated when the program is recompiled.  Or is there a better way?  I have looked around at references to compile time macros but so far not found anything in the way of a basic primer.

dsiders

  • Sr. Member
  • ****
  • Posts: 387
Re: Adding new version no when compiling
« Reply #1 on: September 18, 2020, 12:29:59 pm »
I would like to display a version no on my main form which only changes when the program is compiled.  I read about compile time macros - would this be the way to do it?   Some code in the program to display an incremented number that is only actuated when the program is recompiled.  Or is there a better way?  I have looked around at references to compile time macros but so far not found anything in the way of a basic primer.

You can configure your project to automatically increment version information using the Project > Project Options > Version Info dialog. Just check the "Include version info in executable" and "Automatically increase build number" options.

At run-time you can use the following to access the information: https://wiki.freepascal.org/Show_Application_Title,_Version,_and_Company.
Lazarus 2.1 (SVN) / FPC 3.0.4 / FPC 3.2.0 / x86-win64 / Windows 8.1

jamie

  • Hero Member
  • *****
  • Posts: 3797
Re: Adding new version no when compiling
« Reply #2 on: September 18, 2020, 10:53:44 pm »
Yeah but I wonder how well that is adjusted ?

Does it increment with every successful build and if so, does it do it only at project close time or something that allows me to made it increment ?

 The issue at hand is if I am working in something for 12 hours for example and I like to use the BUILD instead  of compile times because it seems better behaved I don't think I want the build number to increment each time.

 There must be some way for it to be a little smart so that it does not roll the counter on failed compiles or minor changes before closing the project for example or maybe it should ask to increment the build if its successful on a build.
The only true wisdom is knowing you know nothing

440bx

  • Hero Member
  • *****
  • Posts: 2048
Re: Adding new version no when compiling
« Reply #3 on: September 19, 2020, 12:15:43 am »
I have looked around at references to compile time macros but so far not found anything in the way of a basic primer.
That would be a good way to do it.  Unfortunately, there are no predefined macros (at least in the documentation) for things like compile year, month, day, hour, min, sec which would be useful to create a build number.

@dsiders suggestion is probably your best bet at this time.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1062
  • Former Delphi 1-7, 10.2 User
Re: Adding new version no when compiling
« Reply #4 on: September 19, 2020, 02:04:35 am »
Unfortunately, there are no predefined macros (at least in the documentation) for things like compile year, month, day, hour, min, sec which would be useful to create a build number.

Do these new directives which appeared in FPC 3.2.0 help?

* {$include %currentRoutine%} expands to the name of the current routine (string).
* {$include %dateYear%} expands to the year number at time of compilation (smallInt).
* {$include %dateMonth%} expands to the day number in month at time of compilation (shortInt).
* {$include %timeHour%} expands to the number of seconds at time of compilation (shortInt).
* {$include %timeMinute%} expands to the number of minutes at time of compilation (shortInt).
* {$include %timeSecond%} expands to the number of seconds at time of compilation (shortInt).
o Lazarus v2.1.0 r63871, FPC v3.3.1 r47164, macOS 10.14.6, Xcode 11.3.1
o Lazarus v2.1.0 r64160, FPC v3.3.1 Nov 27 21:16:31, macOS 11.0.1 (aarch64), Xcode 12.2
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 20.04 (PD VM)

440bx

  • Hero Member
  • *****
  • Posts: 2048
Re: Adding new version no when compiling
« Reply #5 on: September 19, 2020, 04:46:30 am »
Do these new directives which appeared in FPC 3.2.0 help?

* {$include %currentRoutine%} expands to the name of the current routine (string).
* {$include %dateYear%} expands to the year number at time of compilation (smallInt).
* {$include %dateMonth%} expands to the day number in month at time of compilation (shortInt).
* {$include %timeHour%} expands to the number of seconds at time of compilation (shortInt).
* {$include %timeMinute%} expands to the number of minutes at time of compilation (shortInt).
* {$include %timeSecond%} expands to the number of seconds at time of compilation (shortInt).
They certainly look like they could be used by the OP to build some kind of build/compile version.

Thank you for pointing those out. 
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

dsiders

  • Sr. Member
  • ****
  • Posts: 387
Re: Adding new version no when compiling
« Reply #6 on: September 19, 2020, 06:18:02 am »
Yeah but I wonder how well that is adjusted ?

Does it increment with every successful build and if so, does it do it only at project close time or something that allows me to made it increment ?

 The issue at hand is if I am working in something for 12 hours for example and I like to use the BUILD instead  of compile times because it seems better behaved I don't think I want the build number to increment each time.

 There must be some way for it to be a little smart so that it does not roll the counter on failed compiles or minor changes before closing the project for example or maybe it should ask to increment the build if its successful on a build.

It doesn't sound like you're interested in the "automatic" aspect of it all. If not, don't enable it it and change the numbers when you see fit using the dialog. Or, do what they do  in LCL and LazUtils... use or include the info from a file. Again, you control when it gets incremented.

Personally, I've never found the auto-increment very useful either.  I equate a build number bump with a release process... not just a simple "Build" in the IDE.
Lazarus 2.1 (SVN) / FPC 3.0.4 / FPC 3.2.0 / x86-win64 / Windows 8.1

Thaddy

  • Hero Member
  • *****
  • Posts: 10582
Re: Adding new version no when compiling
« Reply #7 on: September 19, 2020, 01:05:44 pm »
It doesn't sound like you're interested in the "automatic" aspect of it all.
Well, both! of you seem not interested in setting up proper debug and release settings.
The auto increment should be reserved for some kind of release (be it internal, a commit or a release) and the debug settings during development should not touch it.
That is not rocket science. Pressing F9 all the time might overflow the version number at some point... O:-) 8-) ... like about 256's time per dotted part?

The version feature is only meant for serious building, not for development and incrementing all the time.
Setup your builds correctly and it is a very valuable feature. But do use it for any commits, so the executable is verifiable. (the binary, not the commit version)
« Last Edit: September 19, 2020, 01:21:13 pm by Thaddy »

440bx

  • Hero Member
  • *****
  • Posts: 2048
Re: Adding new version no when compiling
« Reply #8 on: September 19, 2020, 05:38:59 pm »
Personally, I've never found the auto-increment very useful either.  I equate a build number bump with a release process... not just a simple "Build" in the IDE.
Quite understandable but, using a manual mechanism leaves open the possibility of forgetting incrementing the build number (admittedly unlikely but possible in that case.)
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 3797
Re: Adding new version no when compiling
« Reply #9 on: September 19, 2020, 08:41:21 pm »
I think there could be an option at project close or IDE close to ask if you want to increment the build on a final compile.

 Also, before performing a publish operation , also ask this so that is a flag is set to increment it due to a recent successful build with changes of course if could serve as a reminder.
The only true wisdom is knowing you know nothing

furious programming

  • Sr. Member
  • ****
  • Posts: 468
  • I click a little.
    • TreeStructInfo — format for text and binary configuration files
Re: Adding new version no when compiling
« Reply #10 on: September 22, 2020, 05:13:52 am »
I would like to display a version no on my main form which only changes when the program is compiled.

In one of my projects I am doing something similar (or the same). The About tab displays, among others program name and current file version. The version is read from the resources of the executable file at runtime and entered on the regular label.

Example:

Code: Pascal  [Select][+][-]
  1. uses
  2.   FileInfo;
  3.  
  4. procedure TMyForm.UpdateVersionLabel();
  5. var
  6.   VersionInfo: TFileVersionInfo;
  7. begin
  8.   VersionInfo := TFileVersionInfo.Create(nil);
  9.   try
  10.     VersionInfo.ReadFileInfo();
  11.     VersionLabel.Caption := VersionInfo.VersionStrings.Values['FileVersion'];
  12.   finally
  13.     VersionInfo.Free();
  14.   end;
  15. end;

Tested on Windows, don't know about other platforms.
Lazarus 2.0.10 with FPC 3.2.0 (SVN Revision 63526), Windows XP (all 32-bit)

josh

  • Hero Member
  • *****
  • Posts: 792
Re: Adding new version no when compiling
« Reply #11 on: September 22, 2020, 10:31:16 am »
Quote
You can configure your project to automatically increment version information using the Project > Project Options > Version Info dialog. Just check the "Include version info in executable" and "Automatically increase build number" options.

This would be ideal for me, but unfortunately when you set this, it is a global settings and impacts all builds; if it was saved per build then it would indeed be usefull. ( Unless this has been fixed in recently).

If the individual build info; could be saved with each build it would be much more flexible; as the Version Info->Other Info is also globally set; this area is handy for putting details specific to the build but only if it alterable per build.
« Last Edit: September 22, 2020, 10:33:22 am by josh »
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

 

TinyPortal © 2005-2018