Collection which can stream itself

The streamcoll unit contains the implentation of a collection (and corresponding collection item) which implements routines for saving or loading the collection to/from a stream. The collection item should implement 2 routines to implement the streaming; the streaming itself is not performed by the collection item.

The streaming performed here is not compatible with the streaming implemented in the Classes unit for components. It is independent of the latter and can be used without a component to hold the collection.

The collection item introduces mostly protected methods, and the unit contains a lot of auxiliary routines which aid in streaming.

Collection and stream classes Exception support Collection item with streaming support

TStreamCollectionItem is a TCollectionItem descendent which implements 2 abstract routines: LoadFromStream and SaveToStream which must be overridden in a descendent class.

These 2 routines will be called by the to save or load the item from the stream.

Collection with stream support

TStreamCollection is a TCollection descendent which implements 2 calls LoadFromStream and SaveToStream which load and save the contents of the collection to a stream.

The collection items must be descendents of the class for the streaming to work correctly.

Note that the stream must be used to load collections of the same type.

Load the collection from a stream LoadFromStream loads the collection from the stream S, if the collection was saved using SaveToStream. It reads the number of items in the collection, and then creates and loads the items one by one from the stream. An exception may be raised if the stream contains invalid data. Stream to load collection from. Load the collection from the stream. SaveToStream saves the collection to the stream S so it can be read from the stream with LoadFromStream. It does this by writing the number of collection items to the stream, and then streaming all items in the collection by calling their SaveToStream method. None. Stream to save collection to Indicates whether the collection is currently being written to stream Streaming is set to True if the collection is written to or loaded from stream, and is set again to False if the streaming process is finished. Exception raised when an error occurs when streaming the collection. Write a 32-bit integer to a stream ColWriteInteger writes the 32-bit integer AValue to the stream S. No endianness is observed. Stream to write integer to Integer value to write to stream Write a boolean to a stream ColWriteBoolean writes the boolean AValue to the stream. S. Stream to write value to Boolean value to write to stream Write a string value to the stream ColWriteString writes the string value AValue to the stream S. Stream to write string value to String value to write to stream Write a currency value to stream ColWriteCurrency writes the currency AValue to the stream S. Stream to write currency to Currency value to write to stream Write a TDateTime value to stream ColWriteDateTime writes the TDateTime AValue to the stream S. Stream to write datetime value to DateTime value to write to stream Write floating point value to stream ColWriteFloat writes the double AValue to the stream S. Stream to write float value to Double value to write to the stream Read a 32-bit integer from a stream. ColReadInteger reads a 32-bit integer from the stream S as it was written by and returns the read value. The value cannot be read and written across systems that have different endian values. Integer value read from stream S Stream to read integer value from Read a boolean value from a stream ColReadBoolean reads a boolean from the stream S as it was written by and returns the read value. The value cannot be read and written across systems that have different endian values. Boolean value read from the stream Stream to read boolean value from Read a string from a stream ColReadStream reads a string value from the stream S as it was written by and returns the read value. The value cannot be read and written across systems that have different endian values. String value read from the stream Stream to read string value from Read a currency value from the stream ColReadCurrency reads a currency value from the stream S as it was written by and returns the read value. The value cannot be read and written across systems that have different endian values. Currency value read from the stream Stream to read currency value from Read a TDateTime value from a stream ColReadDateTime reads a currency value from the stream S as it was written by and returns the read value. The value cannot be read and written across systems that have different endian values. TDateTime value read from the stream Stream to read TDateTime value from Read a floating point value from a stream ColReadFloat reads a double value from the stream S as it was written by and returns the read value. The value cannot be read and written across systems that have different endian values. Float value read from the stream Stream to read float value from.