[Overview][Types][Classes][Index] | Reference for unit 'resdatastream' (#fcl-res)

# TResourceDataStream

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

Stream class that provides copy-on-write functionality

## Declaration

Source position: resdatastream.pp line 61

`type TResourceDataStream = class(TStream)`
`protected`
`function GetPosition; override;`
`procedure SetPosition(); override;`
`function GetSize; override;`
`procedure SetSize64(); override;`
`public`
`constructor Create();` |  | Creates a new object
`destructor Destroy; override;`
`function Compare();` |  | Compares the stream to another one
`procedure SetCustomStream();` |  | Sets a custom stream as the underlying stream
`function Read(); override;`
`function Write(); override;`
`function Seek(); override;`
`property Cached: Boolean; [rw]` |  | Controls the copy-on-write behaviour of the stream
`end;`

## Inheritance

`TResourceDataStream` |  | Stream class that provides copy-on-write functionality
`TStream`
`TObject`

## Description

This class provides the copy-on-write mechanism of TAbstractResource.RawData, via more levels of indirection.

It uses an underlying stream, to which it redirects operations.

The underlying stream can be a TCachedDataStream descendant, a memory stream or a custom stream. Usually when a resource is loaded from a stream, the underlying stream is a TCachedDataStream descendant, which provides a read-only stream-like interface over a portion of the original stream (that is, the part of the original stream where resource data resides). When TResourceDataStream is requested to write data, it replaces the underlying stream with a memory stream, whose contents are copied from the previous underlying stream: this way, copy-on-write functionality can be achieved.

As said before, third possibility is to have a custom stream as the underlying stream: a user can set this stream via TAbstractResource.SetCustomRawDataStream method, which in turn calls TResourceDataStream.SetCustomStream

Figure: Levels of indirection

    .
                         TResourceDataStream
                                  |
           _______________________|_______________________________
          |                       |                               |
    TMemoryStream     TCachedDataStream descendant          custom stream
                             /           \
     _______________________|_____________|______________________________
    |                o r i g|i n a l   s t|r e a m                       |
    |_______________________|_____________|______________________________|

## See also

TCachedDataStream |  | Base cached stream class
TResourceDataStream.Create |  | Creates a new object
TResourceDataStream.SetCustomStream |  | Sets a custom stream as the underlying stream