Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

TPJVersionNumber record

Project: Version Information Component

Unit: PJVersionInfo

Applies to: ~>3.0

TPJVersionNumber = record
  V1: Word;   // Major version number
  V2: Word;   // Minor version number
  V3: Word;   // Revision version number
  V4: Word;   // Build number
end;

Description

V1 represents the most significant version number and V4 represents the least significant number. For example a version number written as 2.5.8.3 would be stored in a variable of type TPJVersionNumber with V1=2, V2=5, V3=8 and V4=3.

Common uses for these fields are shown in the comments in the record definition above.

Enhanced Functionality [~>3.3]

When compiled with Delphi 2006 and later TPJVersionNumber has some additional functionality. This functionality depends on the availability of advanced records, which were introduced with Delphi 2006.

The revised record declaration is:

// ~>3.3 version of TPJVersionNumber
TPJVersionNumber = record
  V1: Word;   // Major version number
  V2: Word;   // Minor version number
  V3: Word;   // Revision version number
  V4: Word;   // Build number
  {$IFDEF Supports_AdvancedRecords} // Delphi 2006 & later
  class operator Implicit(Ver: TPJVersionNumber): string;
  class operator LessThanOrEqual(Ver1, Ver2: TPJVersionNumber): Boolean;
  class operator LessThan(Ver1, Ver2: TPJVersionNumber): Boolean;
  class operator GreaterThan(Ver1, Ver2: TPJVersionNumber): Boolean;
  class operator GreaterThanOrEqual(Ver1, Ver2: TPJVersionNumber): Boolean;
  class operator Equal(Ver1, Ver2: TPJVersionNumber): Boolean;
  class operator NotEqual(Ver1, Ver2: TPJVersionNumber): Boolean;
  {$ENDIF}
end;

String Assignment

A TPJVersionNumber record can be assigned to a string variable. The version number is stored in the string as a dotted quad.

If the following code is executed the string variable S will have the value '2.5.8.3'.

var
  S: string;
  VN: TPJVersionNumber;
begin
  VN.V1 := 2;
  VN.V2 := 5;
  VN.V3 := 8;
  VN.V4 := 3;
  S := VN;
  // ...
end;

You cannot reverse this assignment - a string cannot be assigned to a TPJVersionNumber record.

Users of Delphi 2005 and earlier can use the VerNumToStr [~>3.3] routine to convert a TPJVersionNumber to a string.

Operator Overloads

TPJVersionNumber records can be compared with each other using all the usual equality operators, i.e. =, <>, <, <=, > and >=. This is particularly useful when checking the version numbers of two copies of an executable file to find which one is the latest version.

For example:

var
  VI1, VI2: TPJVersionInfo;
begin
  VI1 := nil;
  VI2 := nil;
  try
    VI1 := TPJVersionInfo.Create(nil);
    VI2 := TPJVersionInfo.Create(nil);
    VI1.FileName := 'C:\Path\To\Program1.exe';
    VI2.FileName := 'C:\Path\To\Program2.exe';
    if not VI1.HaveInfo or not VI2.HaveInfo then
      Exit;  // no version info available
    if VI1.FileVersionNumber > VI2.FileVersionNumber then
    begin
      // Program1.exe has later version than Program2.exe
    end;
  finally
    VI1.Free;
    VI2.Free;
  end;
end;

Users of Delphi 2005 and earlier can use the CompareVerNums [~>3.3] routine to compare two version numbers.