Skip to content

TResources

A collection of resources

Declaration

Source position: resource.pp line 217

type

  TResources = class
  public
    constructor Create;
    destructor Destroy;
    procedure Add;
    function AddAutoID : TResID;
    procedure Clear;
    function Find(aType: TResourceDesc; aName: TResourceDesc; 
             const aLangID: TLangID) : TAbstractResource; overload;
    function Find(aType: TResourceDesc; aName: TResourceDesc)
              : TAbstractResource; overload;
    function Find(const aType: TResName; const aName: TResName; 
             const aLangID: TLangID) : TAbstractResource; overload;
    function Find(const aType: TResName; const aName: TResID; 
             const aLangID: TLangID) : TAbstractResource; overload;
    function Find(const aType: TResID; const aName: TResName; 
             const aLangID: TLangID) : TAbstractResource; overload;
    function Find(const aType: TResID; const aName: TResID; 
             const aLangID: TLangID) : TAbstractResource; overload;
    function Find(const aType: TResName; const aName: TResName)
              : TAbstractResource; overload;
    function Find(const aType: TResName; const aName: TResID)
              : TAbstractResource; overload;
    function Find(const aType: TResID; const aName: TResName)
              : TAbstractResource; overload;
    function Find(const aType: TResID; const aName: TResID)
              : TAbstractResource; overload;
    class function FindReader(aStream: TStream; aExtension: string)
                          : TAbstractResourceReader;
    class function FindReader(aStream: TStream) : TAbstractResourceReader;
    procedure MoveFrom;
    function Remove(aType: TResourceDesc; aName: TResourceDesc; 
               const aLangID: TLangID) : TAbstractResource; overload;
    function Remove(aType: TResourceDesc; aName: TResourceDesc)
                : TAbstractResource; overload;
    function Remove(aResource: TAbstractResource) : TAbstractResource; overload;
    function Remove(aIndex: Integer) : TAbstractResource; overload;
    procedure LoadFromStream(aStream: TStream); overload;
    procedure LoadFromStream(aStream: TStream; 
                        aReader: TAbstractResourceReader); overload;
    procedure LoadFromFile(aFileName: string); overload;
    procedure LoadFromFile(aFileName: string; 
                      aReader: TAbstractResourceReader); overload;
    class procedure RegisterReader;
    class procedure RegisterWriter;
    procedure WriteToStream;
    procedure WriteToFile(aFileName: string); overload;
    procedure WriteToFile(aFileName: string; 
                     aWriter: TAbstractResourceWriter); overload;
    property Count: LongWord; {r}
    property Items[Index : Integer]: TAbstractResource; {r}
    property CacheData: Boolean; {rw}
  end;

Inheritance

Description

This class represents a format-independent view of a resource file. It holds a collection of resources (TAbstractResource descendants).

Typically, a TResource object is loaded from and written to a stream via format-dependent readers and writers, which are descendants of TAbstractResourceReader and TAbstractResourceWriter, respectively.

Single resources can be added, removed, searched and modified: a resource compiler or editor probably will create resources, set their data, and add them to a TResources object which can then be written to file in the desired format.

This class also provides some class methods to register and find resource readers and writers: these classes, once registered, will be used by a TResources object when it is asked to load or save itself to a stream and the user didn't specify a reader or writer.

Remark:

Because of the copy-on-write mechanism of TAbstractResource, care should be taken when loading resources, since by default resource data isn't immediately read from the stream: resources hold a reference to the original stream because they need it when their data is requested. For further information, see TResources.LoadFromStream and TResources.LoadFromFile.

Properties

Member Visibility Description
CacheData public Controls the copy-on-write behaviour of all resources
Count read only public The number of resources in the object
Items read only public Indexed array of resources in the object

Methods

Member Visibility Description
Add public Adds a resource
AddAutoID public Adds a resource and gives it a new autogenerated name
Clear public Deletes all resources
Create public Creates a new TResources object
Destroy public Destroys the object
Find public Searches for a resource
FindReader public Searches for a suitable resource reader
LoadFromFile public Loads the contents of the object from a file
LoadFromStream public Loads the contents of the object from a stream
MoveFrom public Moves all resources of another TResources object to itself
RegisterReader public Registers a resource reader class
RegisterWriter public Registers a resource writer class
Remove public Removes a resource
WriteToFile public Writes the contents of the object to a file
WriteToStream public Writes the contents of the object to a stream

See also

Name Description
TAbstractResource Base abstract resource class
TAbstractResourceReader Base abstract resource reader class
TAbstractResourceWriter Base abstract resource writer class