Skip to content

TVersionResource

Version information resource type

Declaration

Source position: versionresource.pp line 44

type

  TVersionResource = class(TAbstractResource)
  protected
    function GetType : TResourceDesc;
    function GetName : TResourceDesc;
    function ChangeDescTypeAllowed : Boolean;
    function ChangeDescValueAllowed : Boolean;
    procedure NotifyResourcesLoaded;
  public
    constructor Create;
    constructor Create(aType: TResourceDesc; aName: TResourceDesc);
    destructor Destroy;
    procedure UpdateRawData;
    property FixedInfo: TVersionFixedInfo; {r}
    property StringFileInfo: TVersionStringFileInfo; {r}
    property VarFileInfo: TVersionVarFileInfo; {r}
  end;

Description

This class represents a resource of type RT_VERSION.

A resource of this type provides version information for a Microsoft Windows executable or dll, which is shown when checking properties of a file in Windows Explorer.

Information is stored in FixedInfo, StringFileInfo and VarFileInfo.

Remark:

This class doesn't allow its type to be changed to anything else than RT_VERSION, and its name to be different from 1. Attempts to do so result in a EResourceDescChangeNotAllowedException.

Remark:

If you need to access RawData after you modified something, be sure to call UpdateRawData first. This isn't needed however when resource is written to a stream, since TResources takes care of it.

Sample code

This code creates a version information resource

const
  myVersion : TFileProductVersion = (1,2,0,0);

var
  resources : TResources;
  aRes : TVersionResource;
  st : TVersionStringTable;
  ti : TVerTranslationInfo;
begin
  aRes:=TVersionResource.Create(nil,nil); //it's always RT_VERSION and 1 respectively
  resources:=TResources.Create;
  resources.Add(aRes);

  aRes.FixedInfo.FileVersion:=myversion;
  aRes.FixedInfo.ProductVersion:=myversion;
  aRes.FixedInfo.FileFlagsMask:=VS_FFI_FILEFLAGSMASK;
  aRes.FixedInfo.FileFlags:=0;
  aRes.FixedInfo.FileOS:=VOS_NT_WINDOWS32;
  aRes.FixedInfo.FileType:=VFT_APP;
  aRes.FixedInfo.FileSubType:=0;
  aRes.FixedInfo.FileDate:=0;

  st:=TVersionStringTable.Create('041004B0'); //Italian, unicode codepage
  st.Add('CompanyName','Foo Corporation');
  st.Add('FileDescription','Foo suite core program');
  st.Add('FileVersion','1.2');
  st.Add('ProductVersion','1.2');
  aRes.StringFileInfo.Add(st);

  ti.language:=$0410; //Italian
  ti.codepage:=$04B0; //Unicode codepage
  aRes.VarFileInfo.Add(ti);

  resources.WriteToFile('myresource.res');
  resources.Free; //destroys aRes as well.
end;

Properties

Member Visibility Description
FixedInfo read only public Language independent part of version information
StringFileInfo read only public Language dependent part of version information
VarFileInfo read only public List of supported languages
See all Properties

Methods

Member Visibility Description
ChangeDescTypeAllowed protected
ChangeDescValueAllowed protected
Create public Creates a new version information resource
Destroy public
GetName protected
GetType protected
NotifyResourcesLoaded protected
UpdateRawData public
See all Methods

See also

Name Description
TVersionResource.FixedInfo Language independent part of version information
TVersionResource.StringFileInfo Language dependent part of version information
TVersionResource.VarFileInfo List of supported languages