Get VersionInfo for Delphi 2007

posted under by Unknown
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

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

uses
Forms,
VersionInfo,
ApplicationVersionHelper; // Enable the class helper
...
begin
Application.Title := Application.Version['FileDescription'];
end;


-------------------------------------------------------------------------------------

Source Code Sample --> Download

0 赐教

Make A Comment
top