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)

ParameterDescription
lCountNumber of bytes read in the objStream stream.
objStreamStream into which the object should be serialized.
eDirectionIndicates whether the object should be read from or written to the stream.
lSizeNumber 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 0The Serialize event was raised by the Read method
hbStreamWrite1The 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 Sub

Having 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

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A