Recent

Author Topic: [resolved] How to read out the version info set in the Project options  (Read 631 times)

Muso

  • Sr. Member
  • ****
  • Posts: 356
I want to read out the version info I set in the project Option. I found this recipe:
https://wiki.freepascal.org/Show_Application_Title,_Version,_and_Company#FPC_3.0.2B
This does however not work:
*
Code: Pascal  [Select][+][-]
  1. FileVerInfo:=TFileVersionInfo.Create(nil);
has to be
Code: Pascal  [Select][+][-]
  1. FileVerInfo:=TFileVersionInfo.Create;

*
Code: Pascal  [Select][+][-]
  1. FileVerInfo.ReadFileInfo;
does not exist.

How to I cane to load the version info into a TFileVersionInfo?Can anybody update the Wiki page to the current status of FPC 3.2?

I use:
Lazarus 2.2.0 (rev lazarus_2_2_0) FPC 3.2.2 x86_64-win64-win32/win64
« Last Edit: May 19, 2022, 06:59:50 pm by Muso »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: How to read out the version info set in the Project options
« Reply #1 on: May 19, 2022, 06:23:34 pm »
I tested the following code with laz2.2.0-fpc3.2.2/64bit on Win 11, and it compiles and runs without any issue:
Code: Pascal  [Select][+][-]
  1. uses
  2.   fileinfo;
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. var
  6.   FileVerInfo: TFileVersionInfo;
  7.   s: String;
  8. begin
  9.   FileVerInfo := TFileVersionInfo.Create(nil);
  10.   try
  11.     FileVerInfo.ReadFileInfo;
  12.     s := 'Company: ' + FileVerInfo.VersionStrings.Values['CompanyName'] + LineEnding +
  13.          'File description: ' + FileVerInfo.VersionStrings.Values['FileDescription'] + lineEnding +
  14.          'File version: ' + FileVerInfo.VersionStrings.Values['FileVersion'] + LineEnding +
  15.          'Internal name: ' +FileVerInfo.VersionStrings.Values['InternalName'] + LineEnding +
  16.          'Legal copyright: ' + FileVerInfo.VersionStrings.Values['LegalCopyright'] + LineEnding +
  17.          'Original filename: ' + FileVerInfo.VersionStrings.Values['OriginalFilename'] + LineEnding +
  18.          'Product name: ' + FileVerInfo.VersionStrings.Values['ProductName'] + LineEnding +
  19.          'Product version: ' + FileVerInfo.VersionStrings.Values['ProductVersion'];
  20.     ShowMessage(s);
  21.   finally
  22.     FileVerInfo.Free;
  23.   end;
  24. end;

bobby100

  • Full Member
  • ***
  • Posts: 161
    • Malzilla
Re: How to read out the version info set in the Project options
« Reply #2 on: May 19, 2022, 06:42:16 pm »
TVersionInfo from ( \lazarus\lcl\interfaces\mui\vinfo.pas ) works fine if you need just the version (build).

Code: Pascal  [Select][+][-]
  1. var
  2.   Info: TVersionInfo;
  3. begin
  4.   Info := TVersionInfo.Create;
  5.   Info.Load(HINSTANCE);
  6.   // get just the Build Number
  7.   StatusBar1.Panels[0].Text :=
  8.     IntToStr(Info.FixedInfo.FileVersion[0]) + '.' +
  9.     IntToStr(Info.FixedInfo.FileVersion[1]) + '.' +
  10.     IntToStr(Info.FixedInfo.FileVersion[2]) + '.' +
  11.     IntToStr(Info.FixedInfo.FileVersion[3]);
  12.   Info.Free;
  13. end;
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: How to read out the version info set in the Project options
« Reply #3 on: May 19, 2022, 06:59:35 pm »
I tested the following code with laz2.2.0-fpc3.2.2/64bit on Win 11, and it compiles and runs without any issue:
Thanks.This is what I had. I see now that this code worked fine in another program of mine. I found now out the reason it failed for me was that i load other units like versiontypes, versionresource from my previous attempts to get it to work. i removed them et voilá, everything works as described in the Wiki.


 

TinyPortal © 2005-2018