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

# TCachedDataStream

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

Base cached stream class

## Declaration

Source position: resdatastream.pp line 26

`type TCachedDataStream = class(TStream)`
`protected`
`fStream: TStream;` |  | The original stream
`fSize: Int64;` |  | The size of the cached stream
`fPosition: Int64;` |  | The position from the cached stream perspective
`function GetPosition; override;`
`procedure SetPosition(); override;`
`function GetSize; override;`
`procedure SetSize64(); override;`
`public`
`constructor Create(); virtual;` |  | Creates a new object
`function Write(); override;`
`function Seek(); override;`
`end;`

## Inheritance

`TCachedDataStream` |  | Base cached stream class
`TStream`
`TObject`

## Description

This abstract class provides basic cached stream functionalities.

A cached stream is a read-only stream that operates on a portion of another stream. That is, it creates a "window" on the original stream from which to read data. Since it is a read-only stream, trying to write to the stream or to set its size cause an EInvalidOperation exception to be raised.

This class is used by TResourceDataStream to access the raw data of a resource. When an attempt to write to the stream is detected, TResourceDataStream replaces it with a memory stream and copies the contents of the cached stream to the memory one, thus providing a copy-on-write mechanism.

Remark: | An object of this class should never be directly instantiated: use a descendant class instead.

## See also

TResourceDataStream |  | Stream class that provides copy-on-write functionality
TCachedResourceDataStream |  | An implementation of a cached stream

Documentation generated on: May 14 2021