Copyright: PJVersionInfo Help - copyright © 1998-2013 P.D.Johnson (DelphiDabbler)


PJVersionInfo unit

This unit contains the implementation of the TPJVersionInfo version information resource reader component. It also defines the TPJVersionNumber record that stores version numbers as four discreet values.


 TPJVersionInfo

Heirachy          Properties          Methods          Events          Examples

This non-visual component exposes version resource information contained in a file.

Unit

PJVersionInfo

Description

The component reads information from the file's VERSIONINFO resource. If the file has no such resource then this component returns no information. Use the HaveInfo property to find whether the component has been able to get version information from the file.

The file from which resource information is gleaned is determined by the FileName property. The FileName property is the only new design-time property added by this component. Other properties are available at run time only and are used to manipulate and read the version information. The component  supports multi-lingual version resources which have different sets of string information for each language. Use the NumTranslations and CurrentTranslation properties to select the required translation.

TPJVersionInfo introduces no new methods and it has no events.

Further information

For detailed information about file version information see the Windows API VERSIONINFO help topic.


TPJVersionInfo Heirachy
Heirachy

TObject

    |

TPersistent

    |

TComponent


TPJVersionInfo Properties
Properties

>r	CharSet	>r	CharSetCode

>r	Comments	>r	CompanyName

>	CurrentTranslation	>r	FileDescription

>r	FileFlags	>r	FileFlagsMask

FileName	>r	FileOS

>r	FileSubType	>r	FileType

>r	FileVersion	>r	FileVersionNumber

>r	FixedFileInfo	>r	HaveInfo

>r	InternalName	>r	Language

>r	LanguageCode	>r	LegalCopyright

>r	LegalTrademarks	Name

>r	NumTranslations	>r	OriginalFileName

>r	PrivateBuild	>r	ProductName

>r	ProductVersion	>r	ProductVersionNumber

>r	SpecialBuild	>r	StringFileInfo

Tag

Key:

>	Run time property

r	Read-only property


TPJVersionInfo Methods
Methods

TPJVersionInfo adds no methods to those provided by TComponent.


TPJVersionInfo Events
Events

TPJVersionInfo has no events.


TPJVersionInfo.CharSet

TPJVersionInfo          See also          Example

Returns a description of the character set for the current translation.

property CharSet: string;

Description

Run-time and read only. The property contains a string describing the character set whose code is specified by the current translation. If the code is unknown or there is no version information in the current file then the empty string is returned. To examine the actual character set code use the CharSetCode property instead.

See the charsetID section of the Windows API help VERSIONINFO topic for information about these codes.


TPJVersionInfo.CharSetCode

TPJVersionInfo          See also          Example

Returns the code of the character set used by the current translation.

property CharSetCode: WORD;

Description

Run-time and read only. The property specifies the character set code used by the current translation. If the current file has no version information then 0 is returned. To get a description of the character set in English use the CharSet property instead.

See the charsetID section of the Windows API help VERSIONINFO topic for information about these codes.


TPJVersionInfo.Comments

TPJVersionInfo          See also          Example

Returns the string file information Comments string.

property Comments: string;

Description

Run-time and read only. This property stores the value the Comments string for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The StringFileInfo property can also be used to access the value of Comments string by calling StringFileInfo['Comments'].


TPJVersionInfo.CompanyName

TPJVersionInfo          See also          Example

Returns the string file CompanyName string.

property CompanyName: string;

Description

Run-time and read only. This property stores the value the CompanyName string for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The StringFileInfo property can also be used to access the value of CompanyName string by calling StringFileInfo['CompanyName'].


TPJVersionInfo.CurrentTranslation

TPJVersionInfo          See also          Example

Get or set the translation to be used by string, language and character set properties.

property CurrentTranslation: Integer;

Description

Run time only. Version information resources can contain variable information in more that one langauge / character set combination. TPJVersionInfo defines each of these combinations as a "Translation". This property is used to select the translation to be used by the string information, language and character set related properties.

Translations are specified by assigning a zero based index in the CurrentTranslation property. Valid values for CurrentTranslation are in the range0..NumTranslations-1. If an attempt is made to set CurrentTranslation outside this range then the property is given the value -1. CurrentTranslation is set to zero when a file is first accessed (i.e. when the FileName property is assigned or the component is first created) or -1 if there is no version information in a file.

To learn more about the multi-lingual capabilities of version information resources read the VERSIONINFO topic in the Win32 help file.


TPJVersionInfo.FileDescription

TPJVersionInfo          See also          Example

Returns the string file FileDescription string.

property FileDescription: string;

Description

Run-time and read only. This property stores the value the FileDescriptionstring for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The StringFileInfo property can also be used to access the value of FileDescriptionstring by calling StringFileInfo['FileDescription'].


TPJVersionInfo.FileFlags

TPJVersionInfo          See also          Example

Provides information about the release attributes of a file.

property FileFlags: DWORD;

Description

Run-time and read only. This property holds the information (as a bit-set) about the attributes of the file as specified in the fixed file information part of the VERSIONINFO resource.

File flags information is also provided by the dwFileFlags member of the VS_FIXEDFILEINFO structure which can be accessed using the FixedFileInfo property.

The bit set can contain any of the following values:

Flag	Description

VS_FF_DEBUG	File contains debugging information.

VS_FF_INFOINFERRED	Some of the members in this structure may be empty or incorrect.

VS_FF_PATCHED	The file is not identical to the original file with the same version number.

VS_FF_PRERELEASE	The file is a development version.

VS_FF_PRIVATEBUILD	The file is not a standard release. If this flag is set the PrivateBuild property should contain further information.

VS_FF_SPECIALBUILD	The file is a variation of a standard release with the same version number. If this flag is set then the SpecialBuild property should contain further information.

These flags are represented by constants which are defined in the Windows unit.

The FileFlagsMask property determines which of the bits in this flag are valid.


TPJVersionInfo.FileFlagsMask

TPJVersionInfo          See also          Example

Determines which bits of the FileFlags property are valid.

property FileFlagsMask: DWORD;

Description

Run-time and read only. This property contains a bitmask which determines which bits in the FileFlags property are valid. Its value is specified in the fixed file information part of the VERSIONINFO resource. See the FileFlags help topic for details of the available flags.

The value of this this property is also provided by the dwFileFlagsMask field of the VS_FIXEDFILEINFO structure, which can be accessed using the FixedFileInfo property.


TPJVersionInfo.FileName

TPJVersionInfo          See also          Example

Specifies the file from which version information is to be read.

property FileName: string;

Description

This property holds the name of the file from which version information is to be read. A full path name should be provided.

Assigning a file name to this property at run time causes the given file to be checked for version information. The HaveInfo property indicates whether any information was found in the file. When a value is assigned to FileName at design time the component does not immediately check the file for version information - this occurs when the component is created at run-time.

If FileName is assigned the empty string ('') at run-time the component reads version information from the host program. The file name is that given by ParamStr(0). The FileName property is then set to this name. When '' is assigned to FileName at design time it retains this value until run-time when the program name is substituted. This arrangement works well when the component is hosted in an application. When the component is part of a DLL then care should be taken to ensure the name of the file used is as expected.

The default value for FileName is the empty string. This enables the component to automatically read version information from its program file without the user setting any properties or intervening if the program's executable file name is changed.


TPJVersionInfo.FileOS

TPJVersionInfo          See also          Example

Provides information about the operating system for which the application was designed.

property FileOS: DWORD;

Description

Run-time and read only. This property holds information about the operating system for which the file was designed. The value is as specified in the fixed file information part of the VERSIONINFO resource statement.

The value of this this property is also provided by the dwFileOS of the VS_FIXEDFILEINFO structure that is accessed using the FixedFileInfo property.

The value of FileOS is made up of a combination of values. We first specify the host operating system, which can be one of:

Flag	Description

VOS_NT	Windows NT

VOS_DOS	MS-DOS

VOS_OS232	32 bit OS2

VOS_OS216	16 bit OS2

VOS_UNKNOWN	Any (or unspecified) host operating system

We then specify a target operating system that is running on one of the targets above by combining (ORing) one of the above with one of the following values:

Flag	Description

VOS__WINDOWS32	32 bit Windows

VOS__WINDOWS16	Windows 3.x

VOS__PM32	Presentation Manager 32

VOS__PM16	Presentation Manager 16

VOS__BASE	Any, unknown or unspecified target operating system

Some predefined combinations of the above flags are available. They are:

Flag	Description

VOS_DOS_WINDOWS16	Windows 3.x running on MS-DOS

VOS_DOS_WINDOWS32	32 bit Windows runing on MS-DOS

VOS_OS216_PM16	Presentation Manager 16 running on 16 bit OS2

VOS_OS232_PM32	Presentation Manager 32 running on 32 bit OS2

VOS_NT_WINDOWS32	32 bit Windows running on Windows NT

Symbolic constants for all the above flags are defined in the Windows unit.


TPJVersionInfo.FileSubType

TPJVersionInfo          See also          Example

Provides additional file type information for certain file types.

property FileSubType: DWORD;

Description

Run-time and read only. For some file type this property provides additional information about the file type. The information is as specified in the fixed file information part of the VERSIONINFO resource statement.

The value of this property is also provided by the the dwFileSubType member of the VS_FIXEDFILEINFO structure accessed via the FixedFileInfo property.

The value of FileSubType depends on the file type identified by the FileType property, as follows:

•	When FileType has value VFT_FONT (a font file) then valid values of FileSubType are:

Flag	Description

VFT2_UNKNOWN	Font type is unknown.

VFT2_FONT_RASTER	A raster font.

VFT2_FONT_VECTOR	A vector font.

VFT2_FONT_TRUETYPE	A TrueType font.

•	When FileType has value VFT_DRV (a device driver) then FileSubType can take one of the following values:

Flag	Description

VFT2_UNKNOWN	Driver type is unknown.

VFT2_DRV_PRINTER	Printer driver.

VFT2_DRV_KEYBOARD	Keyboard driver.

VFT2_DRV_LANGUAGE	Language driver.

VFT2_DRV_DISPLAY	Display driver.

VFT2_DRV_MOUSE	Mouse driver.

VFT2_DRV_NETWORK	Network driver.

VFT2_DRV_SYSTEM	System driver.

VFT2_DRV_INSTALLABLE	Installable driver.

VFT2_DRV_SOUND	Sound driver.

VFT2_DRV_COMM	Comm port driver(?)

•	When FileType has value VFT_VXD (a virtual device driver) then FileSubType contains the virtual device identifier included in the virtual device control block.

•	In all other cases, and when there is no version information available, FileSubType contains no information and should be zero.

Constants for all the values discussed above are defined in the Windows unit.


TPJVersionInfo.FileType

TPJVersionInfo          See also          Example

Use this property to get information about the type of file - application, DLL etc.

property FileType: DWORD;

Description

Run-time and read only. This property provides information about the type of file being examined. The information is as specified in the fixed file information part of the VERSIONINFO resource statement.

The value of this property is also provided by the the dwFileType member of the VS_FIXEDFILEINFO structure that is accessed using the FixedFileInfo property.

FileType can take one of the values given in the following table. For some types of file further information is provided by the FileSubType property.

Flag	Description

VFT_UNKNOWN	Unknown file type, or no version information is present.

VFT_APP	Application.

VFT_DLL	Dynamic-link library (DLL).

VFT_DRV	Device driver. Further information is provided by the FileSubType property.

VFT_FONT	Font file. Further information is provided by the FileSubType property.

VFT_VXD	Virtual device driver. FileSubType contains the virtual device identifier included in the virtual device control block.

VFT_STATIC_LIB	Static-link library.

Constants for the above values are defined in the Windows unit.


TPJVersionInfo.FileVersion

TPJVersionInfo          See also          Example

Returns the string file FileVersion string.

property FileVersion: string;

Description

Run-time and read only. This property stores the value the FileVersion string for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The StringFileInfo property can also be used to access the value of FileVersion string by calling StringFileInfo['FileVersion'].


TPJVersionInfo.FileVersionNumber

TPJVersionInfo          See also          Example

Use this property to get the version number of a file.

property FileVersionNumber: TPJVersionNumber;

Description

Run-time and read only. This property holds information about the version number of the file being examined. The version number is specified in the fixed file information part of the VERSIONINFO resource statement.

The value of this property is derived from the dwFileVersionMS and dwFileVersionLS members of the VS_FIXEDFILEINFO structure that can be accessed using the FixedFileInfo property. The relationship between the fields of the TPJVersionNumber record returned by this property and dwFileVersionMS and dwFileVersionLS is as follows:

TPJVersionNumber field	VS_FIXEDFILEINFO field

V1	HiWord(dwFileVersionMS)

V2	LoWord(dwFileVersionMS)

V3	HiWord(dwFileVersionLS)

V4	LoWord(dwFiletVersionLS)

The value of this property does not necessarily correspond to the string value given by the FileVersion property as this is separately defined in the VERSIONINFO resource statement.


TPJVersionInfo.FixedFileInfo

TPJVersionInfo          See also          Example

Provides access to the fixed file information record from the current file.

property FixedFileInfo: TVSFixedFileInfo;

Description

Run time and read only. This property exposes the TVSFixedFileInfo record for the current file. All members of the record are set to zeros if the current file contains no version information.

The TVSFixedFileInfo record is identical to the Windows VS_FIXEDFILEINFO structure, and the help topic for that structure in the Win32 help provides help on the purpose of the structure's fields.

TPJVersionInfo provides properties that can be used to directly access information contained in most of the fields of TVSFixedFileInfo. See "see also" above for help on these properties.


TPJVersionInfo.HaveInfo

TPJVersionInfo          See also          Example A          Example B          Example C

HaveInfo informs if the current file contains version information.

property HaveInfo: Boolean;

Description

Run-time and read only. This property has value True if the component has been able to read file version resource information from the file specified by the FileName property. It has value False if there is no version resource information in the file or if an error has occurred reading the file.


TPJVersionInfo.InternalName

TPJVersionInfo          See also          Example

Returns the string file InternalName string.

property InternalName: string;

Description

Run-time and read only. This property stores the value the InternalNamestring for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The StringFileInfo property can also be used to access the value of InternalName string by calling StringFileInfo['InternalName'].


TPJVersionInfo.Language

TPJVersionInfo          See also          Example

Returns a description of the character set for the current translation.

property Language: string;

Description

Run-time and read only. The property returns a string describing the language whose code is specified by the current translation. If the language code is unknown or there is no version information in the current file then the property returns the empty string. To examine the actual language code use the LanguageCode property instead.

See the langID section of the Windows API help VERSIONINFO topic for information about these codes.


TPJVersionInfo.LanguageCode

TPJVersionInfo          See also          Example

Returns the language code associated with the current translation.

property LanguageCode: WORD;

Description

Run-time and read only. The property specifies the language code used by the current translation.  If the current file has no version information then 0 is returned. To get a description of the language use the Language property instead.

See the langID section of the Windows API help VERSIONINFO topic for information about these codes.


TPJVersionInfo.LegalCopyright

TPJVersionInfo          See also          Example

Returns the string file LegalCopyright string.

property LegalCopyright: string;

Description

Run-time and read only. This property stores the value the LegalCopyright string for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The StringFileInfo property can also be used to access the value of LegalCopyright string by calling StringFileInfo['LegalCopyright'].


TPJVersionInfo.LegalTrademarks

TPJVersionInfo          See also          Example

Returns the string file LegalTrademarks string.

property LegalTrademarks: string;

Description

Run-time and read only. This property stores the value the LegalTrademarks string for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The StringFileInfo property can also be used to access the value of LegalTrademarks string by calling StringFileInfo['LegalTrademarks'].


TPJVersionInfo.NumTranslations

TPJVersionInfo          See also          Example

Use this property to find the number of translations in a file's version information.

property NumTranslations: Integer;

Description

Run time and read only. Version information resources can contain variable information in more that one langauge / character set combination. TPJVersionInfo defines each of these combinations as a "Translation". This property shows how many translations are available in a file's version information. The property has value 0 if the file contains no translations or if the file has no version information.

To learn more about the multi-lingual capabilities of version information resources read the VERSIONINFO topic in the Win32 help file.


TPJVersionInfo.OriginalFileName

TPJVersionInfo          See also          Example

Returns the string file OriginalFileName string.

property OriginalFileName: string;

Description

Run-time and read only. This property stores the value the OriginalFileName string for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The StringFileInfo property can also be used to access the value of OriginalFileNamestring by calling StringFileInfo['OriginalFileName'].


TPJVersionInfo.PrivateBuild

TPJVersionInfo          See also          Example

Returns the string file PrivateBuild string.

property PrivateBuild: string;

Description

Run-time and read only. This property stores the value the PrivateBuild string for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The string should only be specified if the VS_FF_PRIVATEBUILD flag is valid and is present in the FileFlags property.

The StringFileInfo property can also be used to access the value of PrivateBuild string by calling StringFileInfo['PrivateBuild'].


TPJVersionInfo.ProductName

TPJVersionInfo          See also          Example

Returns the string file ProductName string.

property ProductName: string;

Description

Run-time and read only. This property stores the value the ProductName string for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The StringFileInfo property can also be used to access the value of ProductName string by calling StringFileInfo['ProductName'].


TPJVersionInfo.ProductVersion

TPJVersionInfo          See also          Example

Returns the string file ProductVersion string.

property ProductVersion: string;

Description

Run-time and read only. This property stores the value the ProductVersion string for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The StringFileInfo property can also be used to access the value of ProductVersionstring by calling StringFileInfo['ProductVersion'].


TPJVersionInfo.ProductVersionNumber

TPJVersionInfo          See also          Example

Use this property to get the version number of the product to which a file relates.

property ProductVersionNumber: TPJVersionNumber;

Description

Run-time and read only. This property holds information about the version number of the product to which the file being examined belongs. The version number is specified in the fixed file information part of the VERSIONINFO resource statement.

The value of this property is derived from the dwProductVersionMS and dwProductVersionLS members of the VS_FIXEDFILEINFO structure that can be accessed using the FixedFileInfo property. The relationship between the fields of the TPJVersionNumber record returned by this property and dwProductVersionMS and dwProductVersionLS is as follows:

TPJVersionNumber field	VS_FIXEDFILEINFO field

V1	HiWord(dwProductVersionMS)

V2	LoWord(dwProductVersionMS)

V3	HiWord(dwProductVersionLS)

V4	LoWord(dwProductVersionLS)

The value of this property does not necessarily correspond to the string value given by the ProductVersion property as this is separately defined in the VERSIONINFO resource statement.


TPJVersionInfo.SpecialBuild

TPJVersionInfo          See also          Example

Returns the string file SpecialBuild string.

property SpecialBuild: string;

Description

Run-time and read only. This property stores the value the SpecialBuild string for the from the StringFileInfo block of the VERSIONINFO resource that is associated with the current translation. If the current file contains no version information then the empty string is returnd.

The string should only be specified if the VS_FF_PRIVATEBUILD flag is valid and is present in the FileFlags property.

The StringFileInfo property can also be used to access the value of SpecialBuild string by calling StringFileInfo['SpecialBuild'].


TPJVersionInfo.StringFileInfo

TPJVersionInfo          See also          Example

Returns the value of string information with the given name.

property StringFileInfo[const Name: string]: string;

Description

Returns the value for string file info with given name for current translation. This property can return both standard and custom string info. If the current file has no version information, or there is no string information for the current name, then the empty string is returned.

For standard string information values either this property or the relevant dedicated property can be used. Standard string information values are:

•	Comments

•	CompanyName

•	FileDescription

•	FileVersion

•	InternalName

•	LegalCopyright

•	LegalTrademarks

•	OriginalFileName

•	PrivateBuild

•	ProductName

•	ProductVersion

•	SpecialBuild

TPJVersionInfo provides a dedicated string property with the same name as each of the above.


TPJVersionNumber

Unit

PJVersionInfo

Description

TPJVersionNumber is a record that stores version numbers from version resources as four discrete values. The record is declared as follows:

TPJVersionNumber = record

  V1, V2, V3, V4: Word;

end;

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 TVersionNumber with V1=2, V2=5, V3=8 and V4=3.

When compiled with Delphi 2006 and later TPJVersionNumber has some additional features:

•	Two TPJVersionNumber records can be compared for equality using the usual =, <>, <, <=, > and >= operators.

•	A TPJVersionNumber record can be directly assigned to a string. Doing this formats the version number as a dotted quad. For example, with the record's fields set as above assigning to a string variable will result in the string '2.5.8.3'.

Two helper functions are also provided, mainly for use with Delphi 2005 and earlier, that perform similar functions:

•	CompareVerNums can be used to compare two version numbers. It returns 0 if the version numbers are the same, negative if the first version number is less than the second or positive if the first is greater than the second.

•	VerNumToStr can be used to format a version number record as a dotted quad string.


Example - Language and CharSets
Example:

Using translation, character set and language properties

This example shows how to use the translation, character set and language properties of TPJVersionInfo to display details of the language and character set for all translations in a file's version info. The example assumes the application contains version information. If this is not the case then a message to that effect is displayed in the list box.

Drop a TListBox and a TPJVersionInfo component on a form and add the following form creation event handler:

procedure TEgForm1.FormCreate(Sender: TObject);

var

  I: Integer;

begin

  ListBox1.Clear;

  // loop thru all translations

  if PJVersionInfo1.HaveInfo then

    for I := 0 to Pred(PJVersionInfo1.NumTranslations) do

    begin

      // make the current translation current

      PJVersionInfo1.CurrentTranslation := I;

      // add language and char set info to the list box

      ListBox1.Items.Add(

        Format(

          'Language: %s (%0.4X) -- CharSet: %s (%0.4X)',

          [PJVersionInfo1.Language, PJVersionInfo1.LanguageCode,

          PJVersionInfo1.CharSet, PJVersionInfo1.CharSetCode]

        )

      );

    end

  else

    ListBox1.Items.Add('NO VERSION INFO');

end;

When the form is displayed details of languages and character sets for each translation are displayed in the list box.


Example - String Info

Example:

Using string information properties

This example demostrates how to access string information from a version resource using TPJVersionInfo. It demonstrates two methods - the first using dedicated properties such as LegalCopyright and the second using the StringFileInfo property. The example also demonstrates the use of the FileName property to access information in other files.

Drop a TMemo, two TButton controls and a TPJVersionInfo component onto a form and add the following function and event handlers:

function DirToPath(const Dir: string): string;

  // Ensures path end in '\'

begin

  if (Dir <> '') and (Dir[Length(Dir)] <> '\') then

    Result := Dir + '\'

  else

    Result := Dir;

end;

function WindowsDir: string;

  // Returns Windows directory

begin

  SetLength(Result, MAX_PATH);

  SetLength(Result, GetWindowsDirectory(PChar(Result), MAX_PATH));

end;

function SystemDir: string;

  // Returns Windows System directory

begin

  SetLength(Result, MAX_PATH);

  SetLength(Result, GetSystemDirectory(PChar(Result), MAX_PATH));

end;

function FindProg(const ExeName: string): string;

  // Finds program in Windows or System directory

begin

  Result := DirToPath(WindowsDir) + ExeName;

  if FileExists(Result) then Exit;

  Result := DirToPath(SystemDir) + ExeName;

  if not FileExists(Result) then

    raise Exception.CreateFmt(

      'Can''t find %s in Windows or System folders', [ExeName]

    );

end;

procedure TEgForm2.Button1Click(Sender: TObject);

begin

  // Get version info for Calc.exe

  PJVersionInfo1.FileName := FindProg('Calc.exe');

  with Memo1.Lines do

  begin

    // Clear the memo and write narrative

    Clear;

    Add('String information block for Windows'

      + ' Calculator (method 1)');

    Add('');

    // Add string information using dedicated properties

    Add('Comments: ' + PJVersionInfo1.Comments);

    Add('CompanyName: ' + PJVersionInfo1.CompanyName);

    Add('FileDescription: ' + PJVersionInfo1.FileDescription);

    Add('FileVersion: ' + PJVersionInfo1.FileVersion);

    Add('InternalName: ' + PJVersionInfo1.InternalName);

    Add('LegalCopyright: ' + PJVersionInfo1.LegalCopyright);

    Add('LegalTrademarks: ' + PJVersionInfo1.LegalTrademarks);

    Add('OriginalFileName: ' + PJVersionInfo1.OriginalFileName);

    Add('PrivateBuild: ' + PJVersionInfo1.PrivateBuild);

    Add('ProductName: ' + PJVersionInfo1.ProductName);

    Add('ProductVersion: ' + PJVersionInfo1.ProductVersion);

    Add('SpecialBuild: ' + PJVersionInfo1.SpecialBuild);

  end;

end;

procedure TEgForm2.Button2Click(Sender: TObject);

  procedure AddStrInfo(StrName: string);

    // Add string info to memo by name

  begin

    Memo1.Lines.Add(StrName + ': ' +

      PJVersionInfo1.StringFileInfo[StrName]);

  end;

begin

  // Get string info for Notepad.exe

  PJVersionInfo1.FileName := FindProg('Notepad.exe');

  // Clear memo and write narrative

  Memo1.Clear;

  Memo1.Lines.Add('String information block for Windows'

      + ' NotePad (method 2)');

  Memo1.Lines.Add('');

  // Add string info using string info names

  AddStrInfo('Comments');

  AddStrInfo('CompanyName');

  AddStrInfo('FileDescription');

  AddStrInfo('FileVersion');

  AddStrInfo('InternalName');

  AddStrInfo('LegalCopyright');

  AddStrInfo('LegalTrademarks');

  AddStrInfo('OriginalFileName');

  AddStrInfo('PrivateBuild');

  AddStrInfo('ProductName');

  AddStrInfo('ProductVersion');

  AddStrInfo('SpecialBuild');

end;

procedure TEgForm2.FormShow(Sender: TObject);

  // ensure the memo is clear

begin

  Memo1.Clear;

end;

When the first button is clicked the memo is populated with string information extracted from the Windows Calculator program while clicking the second button uses a different method to extract and displays string information about the NotePad program.


Example - Fixed File Info (1)

Example:

Using fixed file information properties

This rather long example shows how to use the fixed file information properties. It displays descriptions of the properties in a memo. Most of the example is taken up with code that maps fixed file info codes onto descriptive names. The real meat of the example comes in the form creation event handler at the end of the code.

A similar example shows how to achieve the same results using the FixedFileInfo property.

Drop a TMemo and a TPJVersionInfo component on to a form and enter the following code. The only form method is the form creation event handler.

type

  TTableEntry = record

    // maps codes to descriptions

    Code: DWORD;

    Desc: string;

  end;

const

  cFileType: array[0..6] of TTableEntry =

  (

    (Code: VFT_APP; Desc: 'Application'),

    (Code: VFT_DLL; Desc: 'DLL'),

    (Code: VFT_DRV; Desc: 'Device driver'),

    (Code: VFT_FONT; Desc: 'Font'),

    (Code: VFT_STATIC_LIB; Desc: 'Static link library'),

    (Code: VFT_VXD; Desc: 'Virtual device driver'),

    (Code: VFT_UNKNOWN; Desc: 'Unknown')

  );

  cFileOSBase: array[0..4] of TTableEntry =

  (

    ( Code: VOS_NT; Desc: 'Windows NT' ),

    ( Code: VOS_DOS; Desc: 'MS-DOS' ),

    ( Code: VOS_OS232; Desc: 'OS2 32 bit' ),

    ( Code: VOS_OS216; Desc: 'OS2 16 bit' ),

    ( Code: VOS_UNKNOWN; Desc: 'Any' )

  );

  cFileOSTarget: array[0..4] of TTableEntry =

  (

    ( Code: VOS__WINDOWS32; Desc: '32 bit Windows' ),

    ( Code: VOS__WINDOWS16; Desc: 'Windows 3.x' ),

    ( Code: VOS__PM32; Desc: 'Presentation Manager 32' ),

    ( Code: VOS__PM16; Desc: 'Presentation Manager 16' ),

    ( Code: VOS__BASE; Desc: 'Unknown' )

  );

function CodeToDesc(Code: DWORD;

  Table: array of TTableEntry): string;

  // return description of code using table

var

  I: Integer;

begin

  Result := '';

  for I := Low(Table) to High(Table) do

    if Table[I].Code = Code then

    begin

      Result := Table[I].Desc;

      Break;

    end;

end;

function FileOSDesc(OS: DWORD): string;

  // describe OS

var

  Target, Base: DWORD;

begin

  // get target and base OS

  Target := OS and $0000FFFF;

  Base := OS and $FFFF0000;

  // build description

  if Base = VOS_UNKNOWN then

    Result := CodeToDesc(Target, cFileOSTarget)

  else if Target = VOS__BASE then

    Result := CodeToDesc(Base, cFileOSBase)

  else

    Result := Format('%s on %s',

      [CodeToDesc(Target, cFileOSTarget),

      CodeToDesc(Base, cFileOSBase)]);

end;

function FileFlagsToStr(Flags: DWORD): string;

  // build string of file flags

const

  cFileFlags: array[0..5] of TTableEntry =

  (

    (Code: VS_FF_DEBUG;        Desc: 'Debug'),

    (Code: VS_FF_PRERELEASE;   Desc: 'Pre-release'),

    (Code: VS_FF_PATCHED;      Desc: 'Patched'),

    (Code: VS_FF_PRIVATEBUILD; Desc: 'Private build'),

    (Code: VS_FF_INFOINFERRED; Desc: 'Inferred'),

    (Code: VS_FF_SPECIALBUILD; Desc: 'Special build')  );

var

  I: Integer;

begin

  Result := '';

  for I := Low(cFileFlags) to High(cFileFlags) do

    if Flags and cFileFlags[I].Code = cFileFlags[I].Code then

      Result := Result + #13#10'   ' + cFileFlags[I].Desc

end;

function VerToStr(Ver: TPJVersionNumber): string;

  // return ver number as string

begin

  Result := Format('%d.%d.%d.%d',

    [Ver.V1, Ver.V2, Ver.V3, Ver.V4]);

end;

procedure TEgForm3.FormCreate(Sender: TObject);

begin

  // clear memo

  Memo1.Lines.Clear;

  // check if we have version info

  if PJVersionInfo1.HaveInfo then

    // we have version info: display fixed file info

    with Memo1.Lines do

    begin

      Add('File Version:'#13#10'   '

        + VerToStr(PJVersionInfo1.FileVersionNumber));

      Add('Product Version:'#13#10'   '

        + VerToStr(PJVersionInfo1.ProductVersionNumber));

      Add('File Flags Mask: '

        + FileFlagsToStr(PJVersionInfo1.FileFlagsMask));

      Add('File Flags: '

        + FileFlagsToStr(PJVersionInfo1.FileFlags));

      Add('File Type:'#13#10'   '

        + CodeToDesc(PJVersionInfo1.FileType, cFileType));

      Add('File sub type:');

      case PJVersionInfo1.FileType of

        VFT_FONT, VFT_DRV, VFT_VXD:

          Add(Format('   %0.8X', [PJVersionInfo1.FileSubType]));

        else Add('   None');

      end;

      Add('File OS:'#13#10'   '

        + FileOSDesc(PJVersionInfo1.FileOS));

    end

  else

    Memo1.Lines.Add('NO VERSION INFO');

end;


Example - Fixed File Info (2)

Example:

Using the FixedFileInfo property

This extended example shows how to use the FixedFileInfo property. It displays descriptions of the values of some of the fields of the structure returned by the FixedFileInfo property in a memo. Most of the example is taken up with code that maps fixed file info codes onto descriptive names. The real meat of the example comes in the form creation event handler at the end of the code.

A similar example shows how to achieve the same results using various specialised fixed file information properties.

Drop a TMemo and a TPJVersionInfo component on to a form and enter the following code. The only form method is the form creation event handler.

type

  TTableEntry = record

    // maps codes to descriptions

    Code: DWORD;

    Desc: string;

  end;

const

  cFileType: array[0..6] of TTableEntry =

  (

    (Code: VFT_APP; Desc: 'Application'),

    (Code: VFT_DLL; Desc: 'DLL'),

    (Code: VFT_DRV; Desc: 'Device driver'),

    (Code: VFT_FONT; Desc: 'Font'),

    (Code: VFT_STATIC_LIB; Desc: 'Static link library'),

    (Code: VFT_VXD; Desc: 'Virtual device driver'),

    (Code: VFT_UNKNOWN; Desc: 'Unknown')

  );

  cFileOSBase: array[0..4] of TTableEntry =

  (

    ( Code: VOS_NT; Desc: 'Windows NT' ),

    ( Code: VOS_DOS; Desc: 'MS-DOS' ),

    ( Code: VOS_OS232; Desc: 'OS2 32 bit' ),

    ( Code: VOS_OS216; Desc: 'OS2 16 bit' ),

    ( Code: VOS_UNKNOWN; Desc: 'Any' )

  );

  cFileOSTarget: array[0..4] of TTableEntry =

  (

    ( Code: VOS__WINDOWS32; Desc: '32 bit Windows' ),

    ( Code: VOS__WINDOWS16; Desc: 'Windows 3.x' ),

    ( Code: VOS__PM32; Desc: 'Presentation Manager 32' ),

    ( Code: VOS__PM16; Desc: 'Presentation Manager 16' ),

    ( Code: VOS__BASE; Desc: 'Unknown' )

  );

function CodeToDesc(Code: DWORD;

  Table: array of TTableEntry): string;

  // return description of code using table

var

  I: Integer;

begin

  Result := '';

  for I := Low(Table) to High(Table) do

    if Table[I].Code = Code then

    begin

      Result := Table[I].Desc;

      Break;

    end;

end;

function FileOSDesc(OS: DWORD): string;

  // describe OS

var

  Target, Base: DWORD;

begin

  // get target and base OS

  Target := OS and $0000FFFF;

  Base := OS and $FFFF0000;

  // build description

  if Base = VOS_UNKNOWN then

    Result := CodeToDesc(Target, cFileOSTarget)

  else if Target = VOS__BASE then

    Result := CodeToDesc(Base, cFileOSBase)

  else

    Result := Format('%s on %s',

      [CodeToDesc(Target, cFileOSTarget),

      CodeToDesc(Base, cFileOSBase)]);

end;

function FileFlagsToStr(Flags: DWORD): string;

  // build string of file flags

const

  cFileFlags: array[0..5] of TTableEntry =

  (

    (Code: VS_FF_DEBUG;        Desc: 'Debug'),

    (Code: VS_FF_PRERELEASE;   Desc: 'Pre-release'),

    (Code: VS_FF_PATCHED;      Desc: 'Patched'),

    (Code: VS_FF_PRIVATEBUILD; Desc: 'Private build'),

    (Code: VS_FF_INFOINFERRED; Desc: 'Inferred'),

    (Code: VS_FF_SPECIALBUILD; Desc: 'Special build')  );

var

  I: Integer;

begin

  Result := '';

  for I := Low(cFileFlags) to High(cFileFlags) do

    if Flags and cFileFlags[I].Code = cFileFlags[I].Code then

      Result := Result + #13#10'   ' + cFileFlags[I].Desc

end;

function VerToStr(MS, LS: DWORD): string;

  // return ver number as string

begin

  Result := Format('%d.%d.%d.%d',

    [HiWord(MS), LoWord(MS), HiWord(LS), LoWord(LS)]);

end;

procedure TEgForm3.FormCreate(Sender: TObject);

var

  FFI: TVSFixedFileInfo;

begin

  // clear memo

  Memo1.Lines.Clear;

  // check if we have version info

  if PJVersionInfo1.HaveInfo then

  begin

    // we have version info: display fixed file info

    FFI := PJVersionInfo1.FixedFileInfo;

    with Memo1.Lines do

    begin

      Clear;

      Add('File Version:'#13#10'   '

        + VerToStr(FFI.dwFileVersionMS, FFI.dwFileVersionLS));

      Add('Product Version:'#13#10'   '

        + VerToStr(FFI.dwProductVersionMS, FFI.dwProductVersionLS));

      Add('File Flags Mask: '

        + FileFlagsToStr(FFI.dwFileFlagsMask));

      Add('File Flags: '

        + FileFlagsToStr(FFI.dwFileFlags));

      Add('File Type:'#13#10'   '

        + CodeToDesc(FFI.dwFileType, cFileType));

      Add('File sub type:');

      case FFI.dwFileType of

        VFT_FONT, VFT_DRV, VFT_VXD:

          Add(Format('   %0.8X', [FFI.dwFileSubType]));

        else Add('   None');

      end;

      Add('File OS:'#13#10'   '

        + FileOSDesc(FFI.dwFileOS));

    end

  end

  else

    Memo1.Lines.Add('NO VERSION INFO');

end;