[next] [prev] [prev-tail] [tail] [up]

### 17.16 TResourceFile

     TYPE
        TResourceFile = OBJECT (TObject)
              Stream  : PStream; { File as a stream }
              Modified: Boolean; { Modified flag }
           Constructor Init (AStream: PStream);
           Destructor Done; Virtual;
           Function Count: Sw_Integer;
           Function KeyAt (I: Sw_Integer): String;
           Function Get (Key: String): PObject;
           Function SwitchTo (AStream: PStream; Pack: Boolean): PStream;
           Procedure Flush;
           Procedure Delete (Key: String);
           Procedure Put (Item: PObject; Key: String);
        END;
        PResourceFile = ^TResourceFile;

#### TResourceFile Fields

TResourceFile has the following fields:

Stream
  contains the (file) stream that has the executable image and the resources. It can be initialized by the Init (635) constructor call.
Modified
  is set to True if one of the resources has been changed. It is set by the SwitchTo (635), Delete (637) and Put (637) methods. Calling Flush (637) will clear the Modified flag.

#### TResourceFile.Init

Declaration:
  Constructor TResourceFile.Init (AStream: PStream);
Description:
  Init instantiates a new instance of a TResourceFile object. If AStream is not nil then it is considered as a stream describing an executable image on disk.

  Init will try to position the stream on the start of the resources section, and read all resources from the stream.

Errors:
  None.
See also:
  Done (635)

#### TResourceFile.Done

Declaration:
  Destructor TResourceFile.Done; Virtual;
Description:
  Done cleans up the instance of the TResourceFile Object. If Stream was specified at initialization, then Stream is disposed of too.
Errors:
  None.
See also:
  Init (635)

#### TResourceFile.Count

Declaration:
  Function TResourceFile.Count: Sw_Integer;
Description:
  Count returns the number of resources. If no resources were read, zero is returned.
Errors:
  None.
See also:
  Init (635)

#### TResourceFile.KeyAt

Declaration:
  Function TResourceFile.KeyAt (I: Sw_Integer): String;
Description:
  KeyAt returns the key (the name) of the I-th resource.
Errors:
  In case I is invalid, TCollection.Error will be executed.
See also:
  Get (636)

#### TResourceFile.Get

Declaration:
  Function TResourceFile.Get (Key: String): PObject;
Description:
  Get returns a pointer to a instance of a resource identified by Key. If Key cannot be found in the list of resources, then Nil is returned.
Errors:
  Errors returned may be those by TStream.Get
See also:

#### TResourceFile.SwitchTo

Declaration:
  Function TResourceFile.SwitchTo (AStream: PStream; Pack: Boolean): PStream;
Description:
  SwitchTo switches to a new stream to hold the resources in. AStream will be the new stream after the call to SwitchTo.

  If Pack is true, then all the known resources will be copied from the current stream to the new stream (AStream). If Pack is False, then only the current resource is copied.

  The return value is the value of the original stream: Stream.

  The Modified flag is set as a consequence of this call.

Errors:
  Errors returned can be those of TStream.Read (573) and TStream.Write (574).
See also:
  Flush (637)

#### TResourceFile.Flush

Declaration:
  Procedure TResourceFile.Flush;
Description:
  If the Modified flag is set to True, then Flush writes the resources to the stream Stream. It sets the Modified flag to true after that.
Errors:
  Errors can be those by TStream.Seek (572) and TStream.Write (574).
See also:
  SwitchTo (637)

#### TResourceFile.Delete

Declaration:
  Procedure TResourceFile.Delete (Key: String);
Description:
  Delete deletes the resource identified by Key from the collection. It sets the Modified flag to true.
Errors:
  None.
See also:
  Flush (637)

#### TResourceFile.Put

Declaration:
  Procedure TResourceFile.Put (Item: PObject; Key: String);
Description:
  Put sets the resource identified by Key to Item. If no such resource exists, a new one is created. The item is written to the stream.
Errors:
  Errors returned may be those by TStream.Put (571) and TStream.Seek
See also:
  Get (636)

[next] [prev] [prev-tail] [front] [up]