Obtaining the Version Information

Obtaining the Version Information

The VS_VERSIONINFO structure can be used to obtain file version data about files with extended version data. This structure is not included in Delphi 4.0, nor is it included in any Microsoft SDK. How do I use it and the associated functions to get this version data?

Instead of going into the dirty details of this structure, let me just say that getting the version information revolves around the GetFileVersionInfo Win API call. If you compile your program with extended version information, you can get the version information using this call. However, as with most things in the WinAPI, it’s a lot more complicated than that. Therefore, I’ve created a wrapper class that will handle that stuff for you. All you need to do is create the class and access its properties to get the version information for your executable. Here’s the listing (please observe the copyright info):

{====================================================================== *****PLEASE DO NOT REMOVE THIS HEADER EVEN IF YOU CHANGE THE FILE***** ====================================================================== Author : Brendan V. Delumpa [email protected] Copyright © 1999 Brendan V. Delumpa TITLE Version Info Unit DESCRIPTION This unit can be included in any project to affect version information display in an about box. Simply create and instance of the class, passing a fully qualified file name to the constructor, and the object will retrieve version information about the file. NOTES Since I created this to cover only the functionality I wanted for my own programs, I didn't include everything that you can get with this set of routines. I handle all the return values of GetFileVersion- Info, but only scratch the surface with the PVSFixedFileInfo structure. There's stuff there that I just didn't need. By the way, you're free to use and copy this code to your heart's content. All I ask is that you make sure that you give credit where credit is due. Also, if you make changes, I'd appreciate you sharing them. And if you do, make sure to include your name and e-mail address in the Changes section. Thanks! Brendan EXAMPLE USAGE:  implementation  uses VerInfo; //Merely include this in your uses statement somewhere  procedure TfrmInfo.FormCreate(Sender: TObject);  var    VInfo : TVersionInfo;  begin    with Animate1 do begin      Active := False;      ResName := 'RHS_Act';      Active := True;    end;    VInfo := TVersionInfo.Create(Application.ExeName);    Label1.Caption := VInfo.CompanyName;    Label3.Caption := VInfo.FileVersion;    Label5.Caption := VInfo.LegalCopyright;    Label8.Caption := VInfo.ProductName;    Label9.Caption := VInfo.ProductVersion;    Label11.Caption := VInfo.OSVersion;    VInfo.Free;  end; CHANGES: Date         Who                     What ==========   =====================   ================================= 1/13/1999    Brendan                 Added some example code for when                                      unit is distributed ======================================================================}unit VerInfo;interfaceuses  Windows, SysUtils, Forms;type  TVersionInfo = class  private    FPVSFileInfoBuf         : PVSFixedFileInfo;    FVerInfoSize            : DWORD;    FVersBuffer,    FCompanyNameText,    FFileDescriptionText,    FFileVersionText,    FInternalNameText,    FLegalCopyrightText,    FLegalTrademarksText,    FOriginalFilenameText,    FProductNameText,    FProductVersionText,    FCommentsText             : String;    function GetVersionInfo(FieldString : String) : String;    function GetOSVersion : String;  public    constructor Create(FileName : String);    property CompanyName      : String read FCompanyNameText;    property FileDescription  : String read FFileDescriptionText;    property FileVersion      : String read FFileVersionText;    property InternalName     : String read FInternalNameText;    property LegalCopyright   : String read FLegalCopyrightText;    property LegalTrademarks  : String read FLegalTrademarksText;    property OriginalFilename : String read FOriginalFilenameText;    property ProductName      : String read FProductNameText;    property ProductVersion   : String read FProductVersionText;    property Comments         : String read FCommentsText;    property OSVersion        : String read GetOSVersion;  end;implementationconstructor TVersionInfo.Create(FileName : String);var  Hndl  : DWORD;  iSize : Cardinal;begin  //Get the size of the version information structure  FVerInfoSize := GetFileVersionInfoSize(PChar(FileName), Hndl);  if not (FVerInfoSize 


Share the Post: