Home > Language Reference > Classes > Object
Serialize Event
Event raised to serialize the object content into a stream.
Syntax
Protected Event Serialize(ByRef lCount As Long, ByVal objStream As Stream, ByVal eDirection As HbStream, ByVal lSize As Long)
| Parameter | Description |
| lCount | Number of bytes read in the objStream stream. |
| objStream | Stream into which the object should be serialized. |
| eDirection | Indicates whether the object should be read from or written to the stream. |
| lSize | Number of bytes to serialize. |
Remarks
This event is raised by the Read and Write methods when you try to write the content of an object into a stream, or read the content of an object from a stream. The eDirection argument determines which one of the two operations to carry out.
| Constant | Value | Description |
| hbStreamRead | 0 | The Serialize event was raised by the Read method |
| hbStreamWrite | 1 | The Serialize event was raised by the Write method |
The lSize argument contains the size in bytes specified when calling the Read or Write statements, or hbReadDefault or hbWriteDefault if no size was specified. Most predefined objects do not take this information into account, and you are free to do the same in your own classes.
If necessary, your event handler can set the lCount argument to the number of bytes read; this value will then be returned by the Read function. If your code never relies on the return value of the Read function, you can simply ignore the lCount parameter.
In the following example, a clsContact class is defined, containing two members of type string. An handler for its Serialize event could be:
Public sName As String
Public sPhoneNumber As String
Private Sub Object_Serialize(ByRef lCount As Long, ByVal objStream As Stream, ByVal eDirection As HbStream, ByVal lSize As Long)
Select Case eDirection
Case hbStreamWrite
objStream.Write sName
objStream.Write sPhoneNumber
Case hbStreamRead
objStream.Read sName
objStream.Read sPhoneNumber
End Select
End SubHaving implemented this handler, you can serialize any contact instance of this class in any stream , from anywhere in your project by simply writing:
stream.Write contact
If during the development of your project, new members requiring serialization are added to the clsContact object, only the Serialize handler will have to be modified.
For more information about streams, refer to the documentation of the Stream object.
System requirements
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | N/A |