Sign in Join
FPDoc Onlineexperiment

TVersionResource class

In unit versionresource

Version information resource type

Declaration

pascal
TVersionResource = class(TAbstractResource)

Inheritance

  1. TVersionResource
  2. TAbstractResource

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.

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.
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;

See also

Properties

FixedInfopublicLanguage independent part of version information
StringFileInfopublicLanguage dependent part of version information
VarFileInfopublicList of supported languages

Methods

GetTypeprotectedReturns the type of the resource
GetNameprotectedReturns the name of the resource
ChangeDescTypeAllowedprotectedReports whether changing the type of resource type or name is allowed
ChangeDescValueAllowedprotectedReports whether changing the value of resource type or name is allowed
NotifyResourcesLoadedprotectedTells the resource that all resources have been loaded
CreatepublicCreates a new version information resource
DestroypublicDestroys the object
UpdateRawDatapublicUpdates RawData stream.

Inherited

From TAbstractResource (20)

_Type CacheData Characteristics CodePage CompareContents DataOffset DataSize DataVersion HeaderSize LangID MemoryFlags Name Owner OwnerList RawData SetChildOwner SetCustomRawDataStream SetDescOwner SetOwnerList Version

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.