Declaration¶
Source position: resource.pp line 137
type
TAbstractResource = class
protected
procedure SetDescOwner;
procedure SetOwnerList;
procedure SetChildOwner;
function GetType : TResourceDesc;
function GetName : TResourceDesc;
function ChangeDescTypeAllowed : Boolean;
function ChangeDescValueAllowed : Boolean;
procedure NotifyResourcesLoaded;
constructor Create; overload;
constructor Create(aType: TResourceDesc; aName: TResourceDesc); overload;
public
destructor Destroy;
function CompareContents : Boolean;
procedure UpdateRawData;
procedure SetCustomRawDataStream;
property _Type: TResourceDesc; {r}
property Name: TResourceDesc; {r}
property LangID: TLangID; {rw}
property DataSize: LongWord; {r}
property HeaderSize: LongWord; {r}
property DataVersion: LongWord; {rw}
property MemoryFlags: Word; {rw}
property Version: LongWord; {rw}
property Characteristics: LongWord; {rw}
property DataOffset: LongWord; {r}
property CodePage: LongWord; {rw}
property RawData: TStream; {r}
property CacheData: Boolean; {rw}
property OwnerList: TResources; {r}
property Owner: TAbstractResource; {r}
end;
Inheritance¶
Description¶
This is the base class that represents a resource.
A resource is identified by its type, name and language ID even if some file formats or operating systems don't consider the latter.
There are also additional properties that aren't always present in all file formats, so their values aren't always meaningful: however, they can be used to display detailed information when possible.
Every resource has a RawData stream that holds resource data. This stream uses a copy-on-write mechanism: if the resource has been read from a stream or file, RawData redirects read operations to the original stream. This is particularly useful when a resource file must be converted from a format to another, or when more resource files must be merged, since (potentially large) resource data is directly copied from the original to the destination stream without the need of allocating a lot of memory.
When resource data is encoded in a resource-specific format, RawData can be uncomfortable: it's often better to use a more specialized descendant class that provides additional properties and methods.
Resources cannot be read or written alone from/to a stream: they need to be contained in a TResources object, which represents an abstract view of a resource file.
Usually each descendant registers itself with TResourceFactory class in the initialization section of the unit in which it is implemented: this way TResourceFactory class can know which class to use to instantiate a resource of a given type.
Remark:
Properties¶
| Member | Visibility | Description |
|---|---|---|
| CacheData | public | Controls the copy-on-write behaviour of the resource |
| Characteristics | public | A user defined piece of data |
| CodePage | public | The code page of the resource |
| DataOffset read only | public | The offset of resource data from the beginning of the stream |
| DataSize read only | public | The size of resource raw data |
| DataVersion | public | The version of the resource data |
| HeaderSize read only | public | The size of resource header |
| LangID | public | The language ID of the resource |
| MemoryFlags | public | The memory flags of the resource |
| Name read only | public | The name of the resource |
| Owner read only | public | The owner of this resource |
| OwnerList read only | public | The resource list that owns this resource |
| RawData read only | public | The raw resource data stream |
| Version | public | A user defined version number |
| _Type read only | public | The type of the resource |
Methods¶
| Member | Visibility | Description |
|---|---|---|
| ChangeDescTypeAllowed | protected | Reports whether changing the type of resource type or name is allowed |
| ChangeDescValueAllowed | protected | Reports whether changing the value of resource type or name is allowed |
| CompareContents | public | Compares the contents of the resource to the contents of another one |
| Create | protected | Creates a new resource |
| Destroy | public | Destroys the object |
| GetName | protected | Returns the name of the resource |
| GetType | protected | Returns the type of the resource |
| NotifyResourcesLoaded | protected | Tells the resource that all resources have been loaded |
| SetChildOwner | protected | Protected method to let a resource set itself as the owner of a sub-resource |
| SetCustomRawDataStream | public | Sets a custom stream as the underlying stream for RawData |
| SetDescOwner | protected | Sets this resource as the owner of the given TResourceDesc |
| SetOwnerList | protected | Protected method to let a resource list set itself as the owner of the resource |
| UpdateRawData | public | Updates RawData stream. |
See also¶
| Name | Description |
|---|---|
| TGenericResource | Generic resource class |
| TAcceleratorsResource | Accelerator table resource type |
| TBitmapResource | Bitmap resource type |
| TGroupCursorResource | Group cursor resource type |
| TGroupIconResource | Group icon resource type |
| TStringTableResource | String table resource type |
| TVersionResource | Version information resource type |
| TResources | A collection of resources |
| TResourceFactory | Factory class for resources |