Home > Language Reference > Classes

StreamNull Class

  + Object
    + Stream
      + StreamNull

Description

The StreamNull class implements a null stream. All the data written in this stream is lost, and it is not possible to read from this stream. Its Size and Position properties always return the value zero and the Seek method has no effect. This class is instantiable but not derivable or cloneable.

The following example shows a possible use of a null stream. An application logs events. Depending on the value of a variable stored for example in the system preferences, the events are logged in a file, sent to another device via the serial port, or ignored:

Private objLog as Stream

Public Sub InitLog(ByVal iType As Integer)
  Select Case iType
    Case 0
      Set objLog = New StreamNull
    Case 1
      Dim vfs As New VFSVolume
      vfs.FindFirstVolume
      Set objLog = New StreamFile
      StreamFile(objLog).Open vfs.Reference, "/logfile.txt", hbModeReadWrite+hbModeOpenAlways
    Case 2
      Set objLog = New StreamSerial
      StreamSerial(objLog).Open hbPortSerial, 57600
  End Select
End Sub

Public Sub WriteToLog(ByRef sText As String)
  objLog.Write sText, hbWriteNoNull
  objLog.Write "\r\n", 2
End Sub

The InitLog function should be called when starting the application, passing it a code determining the location of the log file. Depending on the code, the global variable objLog is set to a StreamNull, StreamFile or StreamSerial object. The WriteToLog function writes a string followed by a carriage return into the log file. This last function does not have to worry about the exact type of log file: the Write method behaves the same way on all types of stream.

For more information on streams, refer to the chapter on Data Streams.

Members

Inherited from StreamDescription
Position Stream pointer position.
Read Reads data from a stream.
Seek Moves the stream pointer.
SeekToBegin Moves the pointer to the beginning of the stream.
SeekToEnd Moves the pointer to the end of the stream.
Size Total size of the data in a stream.
Write Writes data to a stream.
Inherited from ObjectDescription
ClassID Returns the type identifier corresponding to the actual class of the object.
Implements Determines whether the object implements the features of a given class.
Iterate Event raised to iterate over the elements of a container object.
Recipient Recipient of events sent by the object.
Serialize Event raised to serialize the object content into a stream.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A