17.15 TResourceCollection

A TResourceCollection manages a collection of resource names. It stores the position and the size of a resource, as well as the name of the resource. It stores these items in records that look like this:

 TYPE
    TResourceItem = packed RECORD
       Posn: LongInt;
       Size: LongInt;
       Key : String;
    End;
    PResourceItem = ^TResourceItem;

It overrides some methods of TStringCollection in order to accomplish this.

Remark that the TResourceCollection manages the names of the resources and their assiciated positions and sizes, it doesn’t manage the resources themselves.

Here is the full declaration of the TResourceCollection object:

 TYPE
    TResourceCollection = OBJECT (TStringCollection)
       Function KeyOf (Item: Pointer): Pointer; Virtual;
       Function GetItem (Var S: TStream): Pointer; Virtual;
       Procedure FreeItem (Item: Pointer); Virtual;
       Procedure PutItem (Var S: TStream; Item: Pointer); Virtual;
    END;
    PResourceCollection = ^TResourceCollection;

TResourceCollection.KeyOf

Declaration:
Function TResourceCollection.KeyOf (Item: Pointer): Pointer; Virtual;
Description:
KeyOf returns the key of an item in the collection. For resources, the key is a pointer to the string with the resource name.
Errors:
None.
See also:
TStringCollection.Compare (620)

TResourceCollection.GetItem

Declaration:
Function TResourceCollection.GetItem (Var S: TStream): Pointer; Virtual;
Description:
GetItem reads a resource item from the stream S. It reads the position, size and name from the stream, in that order. It DOES NOT read the resource itself from the stream.

The resulting item is not inserted in the collection. This call is manly for internal use by the TCollection.Load (594) method.

Errors:
Errors returned are those by TStream.Read (573)
See also:
TCollection.Load (594), TStream.Read (573)

TResourceCollection.FreeItem

Declaration:
Procedure TResourceCollection.FreeItem (Item: Pointer); Virtual;
Description:
FreeItem releases the memory occupied by Item. It de-allocates the name, and then the resourceitem record.

It does NOT remove the item from the collection.

Errors:
None.
See also:
TCollection.FreeItem (605)

TResourceCollection.PutItem

Declaration:
Procedure TResourceCollection.PutItem (Var S: TStream; Item: Pointer); Virtual;
Description:
PutItem writes Item to the stream S. It does this by writing the position and size and name of the resource item to the stream.

This method is used primarily by the Store (609) method.

Errors:
Errors returned are those by TStream.Write (574).
See also:
Store (609)