VersionInfo for Delphi

The VersionInfo library basically just wraps the Win32 GetFileVersionInfo (and related) API functions. The library makes it very easy to read values from the Version Info resource of Windows executables and DLLs.

Features

  • Reads all integer version info values:
    File version, product version, File flags, OS, file type, file sub-type and file date.
  • Reads any named version info string value such as:
    Product Name, Product Version, Company, Copyright, etc.
  • Supports languages, character sets and translations.
  • Optionally extends the TApplication class with a version info property.

The TApplicationVersion class

The TApplicationVersion class contains the core functionality of the library. The following is the public interface of the class:

TApplicationVersion = class
public
  constructor Create(const Filename: string);
  destructor Destroy; override;
  class function VersionToString(Version: int64): string;
  class function StringToVersion(const Value: string): int64;
  function GetString(const Key: string; LanguageID: integer; CharsetID: integer): string; overload;
  function GetString(const Key, TranslationID: string): string; overload;
  function GetString(const Key: string; Index: integer = 0): string; overload;
  property Valid: boolean;
  property Strings[const Key: string]: string; default;
  property FileVersion: int64;
  property ProductVersion: int64;
  property FileFlags: DWORD;
  property OS: DWORD;
  property FileType: DWORD;
  property FileSubType: DWORD;
  property FileDate: int64;
  property LanguageID[Index: integer]: WORD;
  property CharsetID[Index: integer]: WORD;
  property LanguageNames[Index: integer]: string;
  property TranslationCount: integer;
end;

The TApplicationVersionHelper class

As a bonus there’s also a class helper that extends TApplication with a version info property:

TApplicationVersionHelper = class helper for TApplication
public
  property Version: TApplicationVersion;
end;

To enable the class helper you just include the ApplicationVersionHelper unit in your uses clause.

Examples

Example 1

Read the version number from a file and display it in a message box

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
uses
  VersionInfo;
...
const
  Filename = 'foobar.exe';
var
  FVersionInfo: TVersionInfo;
  Version: string;
begin
  FVersionInfo := TVersionInfo.Create(Filename);
  try
    Version := TVersionInfo.VersionToString(FVersionInfo.FileVersion);
  finally
    FVersionInfo.Free;
  end;
  ShowMessage(Format('The file %s has version %s', [Filename, Version]));
end;

Example 2

Set the application title to the description value specified in the version resource

1
2
3
4
5
6
7
8
uses
  Forms,
  VersionInfo,
  ApplicationVersionHelper; // Enable the class helper
...
begin
  Application.Title := Application.Version['FileDescription'];
end;

Requirements

D1 D2 D3 D4 D5 D6 D7 D2005 D2006 D2007
Fail Fail Fail Fail Fail Fail Fail Fail Unknown Pass

Note: The library has only been tested with Delphi 2007, but apart from the class helper, which requires Delphi 2006 or later, I would think the code can be adapted for Delphi 4 and later with minimal modifications.

License

Creative Commons License
This work is licensed under a
Creative Commons Attribution-Share Alike 3.0 Unported License.

Download

download
Download: VersionInfo for Delphi
Version: 1.1
Updated: 2 March, 2008
Size: 9.62 KB
Notes:
Downloads: 7,478

FAQ - Frequently Asked Questions

There are no questions yet.

Change log

  • Version 1.1 (2008-03-02)
    • Moved TVersionInfo and TApplicationVersionHelper to their own units.
    • General release.
  • Version 1.0 (2007-07-28)
    • Cleaned up for production use.
    • Renamed TApplicationVersion to TVersionInfo.
  • Version 0.1 (2007-07-13)
    • Proof of concept demo.