Recent

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

ronhud

  • Jr. Member
  • **
  • Posts: 84
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

  • Hero Member
  • *****
  • Posts: 1045
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.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

jamie

  • Hero Member
  • *****
  • Posts: 6077
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: 3921
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) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • 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).

440bx

  • Hero Member
  • *****
  • Posts: 3921
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) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

dsiders

  • Hero Member
  • *****
  • Posts: 1045
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.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Thaddy

  • Hero Member
  • *****
  • Posts: 14159
  • Probably until I exterminate Putin.
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 »
Specialize a type, not a var.

440bx

  • Hero Member
  • *****
  • Posts: 3921
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) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 6077
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

  • Hero Member
  • *****
  • Posts: 836
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 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

Josh

  • Hero Member
  • *****
  • Posts: 1270
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 »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

 

TinyPortal © 2005-2018