Lazarus

Programming => General => Topic started by: ronhud on September 18, 2020, 10:37:20 am

Title: Adding new version no when compiling
Post by: ronhud 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.
Title: Re: Adding new version no when compiling
Post by: dsiders 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.
Title: Re: Adding new version no when compiling
Post by: jamie 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.
Title: Re: Adding new version no when compiling
Post by: 440bx 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.
Title: Re: Adding new version no when compiling
Post by: trev 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).
Title: Re: Adding new version no when compiling
Post by: 440bx 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. 
Title: Re: Adding new version no when compiling
Post by: dsiders 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.
Title: Re: Adding new version no when compiling
Post by: Thaddy 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)
Title: Re: Adding new version no when compiling
Post by: 440bx 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.)
Title: Re: Adding new version no when compiling
Post by: jamie 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.
Title: Re: Adding new version no when compiling
Post by: furious programming 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.
Title: Re: Adding new version no when compiling
Post by: josh 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.
TinyPortal © 2005-2018