Class TObjStream (unit SuperStream) |
Object stream adapters read and write objects from other streams. It is often useful to couple this adapter with a buffering adapter, as object streams frequently read and write with thousands of small byte count io operations.
Constructors |
Functions |
Properties |
Events |
Variables |
Constructors |
Parameter | Description |
---|---|
stream | The stream to read or write objects to/from. |
owned | If true, the target stream will be freed when the object stream is freed. |
options | Options from the TobjStreamOption type. |
Construct an object stream.
Parameter | Description |
---|---|
fn | The file to use for streaming. |
options | Options from the TObjStreamOption type. |
dir | The IO direction (iodirRead, iodirWrite). |
Construct an object stream on a file. The stream will be buffered internally. You must also specify whether you intend to read or write from the stream.
Functions |
Destroy a stream adapter. Will also destroy the target stream if the owned flag is set true.
Flush the list of objects written/read. This is useful if you are resetting the stream to read it again.
Read an object from the stream. The object's class must have been registered. IO routines for subclasses will automatically be called.
Parameter | Description |
---|---|
filename | The file to read the object from. |
Reads a single object from a file, very conveniently.
Parameter | Description |
---|---|
obj | An already constructed empty object to read values into. |
io | The io procedure to use for this read or write only. |
version | The version number to pass to the io procedure. |
callSuperClassIO | If true, the object's superclass io procedure will be called after the specified io procedure is called. |
Read an object from the stream using the given io procedure.
Parameter | Description |
---|---|
cls | The class being registered. |
_writer | An io procedure for the class. |
latest | The current version number for the class (an integer). The version number will usually be incremented each time the structure of the object changes. |
Register class notifies the streaming system of a persistent capable class.
Parameter | Description |
---|---|
cls | The class being registered. |
_writer | An io procedure for the class. |
latest | The current version number for the class (an integer). The version number will usually be incremented each time the structure of the object changes. |
init | Object initializer. |
Register class notifies the streaming system of a persistent capable class.
Assigns default io procedures for some of Delphi's classes. If this is not called, io procedures will have to be registered for all classes. IO procedures are registered for TStringList and TObjList. TObjList is a list of objects, and is contained within this unit.
Parameter | Description |
---|---|
firstItem | An open array of the first item of each array. |
firstItemAddresses | An open array of the addresses of the first item in each array. |
counts | An open array containing a count for each array to be written. |
direction | iodirRead or iodirWrite, depending on whether read or write is desired. |
Use TransferArrays to load and store multiple arrays of atomic values.
Parameter | Description |
---|---|
firstItem | An open array of the first item of each array. |
firstItemAddresses | An open array of the addresses of the first item in each array. |
itemTypes | An open array of ssvt constants indicating the type of each array. |
counts | An open array containing a count for each array to be written. |
direction | iodirRead or iodirWrite, depending on whether read or write is desired. |
Use TransferArrays to load and store multiple arrays of atomic values, with additional type information.
Parameter | Description |
---|---|
addresses | An open array of pointers to the blocks. |
sizes | An open array of the sizes of each block. |
direction | iodirRead or iodirWrite, depending on whether read or write is desired. |
Use TransferBlocks to load and store blocks of memory in an object stream.
Parameter | Description |
---|---|
item | The item to transfer. |
itemAddress | Where the item is. |
direction | Whether to read or write. |
TransferItem is used to read or write a single TVarRec-based object. This is very useful for writing the SDL classes, which store DObjects that are equivalent to TVarRec.
Parameter | Description |
---|---|
item | The item to transfer. |
itemAddress | Where the item is. |
itemType | The type of the variable (ssvt constant). |
direction | Whether to read or write. |
TransferItemEx is used to read or write a single TVarRec-based object, supplying a specific type.
Parameter | Description |
---|---|
items | An array of items to read or write. The items should be encased in square brackets: [a,b,c]. This is Delphi's open array syntax. |
itemAddresses | Pointers to each of the variables passed in items, also in open array format: [@a, @b, @c]. |
direction | Either iodirRead or iodirWrite, depending on whether objects are being read or written. |
version | This will contain the version number of the object read in. |
Use TransferItems to load and store atomic values. Be careful with floating point -- it doesn't provide a way to do single and double, yet, because there's no way to distinguish those types. If you want to do singles, doubles, or TDateTime, use the TransferItemsEx call instead, which lets you specify the types of your members.
Parameter | Description |
---|---|
items | An array of items to read or write. The items should be encased in square brackets: [a,b,c]. This is Delphi's open array syntax. |
itemAddresses | Pointers to each of the variables passed in items, also in open array format: [@a, @b, @c]. |
itemTypes | The itemTypes open array exists so that atomic types
not handled by Delphi's open array system can be
used. Each variable in the items parameter should
have, in itemTypes, a corresponding type indicator.
Note that this is usually only necessary of SINGLE
or DOUBLE values are going to be written. Here are the possible values:
|
direction | Either iodirRead or iodirWrite, depending on whether objects are being read or written. |
version | This will contain the version number of the object read in. |
Transfer items to and from the stream, with type information. If you need to distinguish between different forms of floating point, use this routine instead. itemTypes is an array of ssvt codes (see the top of this file) that correspond to the atomic data types. You can use ssvtNone if you want the default mechanism to handle it. The best way to use this is to stream your singles and doubles first, then the rest of your items. The list of itemtypes doesn't have to be the same length as the list of items to transfer -- ssvtNone will be assumed for the remaining items if the list is shorter.
The most common use of this routine is to transfer single or double floating point values, whose type is not handled accurately by the array of const system Delphi provides.
TransferVarRec does the io for a single TVarRec, where that TVarRec is the actual storage location for the value.
Parameter | Description |
---|---|
obj | The object to write. |
Write an object to the stream. The object's class must have been registered. IO routines for subclasses will automatically be called.
Parameter | Description |
---|---|
filename | The file to write the object info. |
obj | The object to write. The object must have its class registered. |
Writes a single object to a file, conveniently.
Parameter | Description |
---|---|
obj | The object to write. |
io | The io procedure to use. |
version | The version number that will be passed to the io procedure. |
callSuperClassIO | Indicates whether the object's superclass io procedures will be called after the specified io procedure is called. |
Write an object to the stream using the given io procedure.
Properties |
Events |
If assigned, this event will be fired whenever a new object is created. This gives the program a chance to alter the construction of the new object.
Variables |