|
|
Date: |
11-04-2006 |
File
Size: |
11.0
KB |
VO-Versions: |
Visual
Objects 2.7
CA-Visual
Objects 2.6
CA-Visual Objects 2.5b-3
CA-Visual Objects 2.0b-4 |
|
|
|
With
the class bStream arbitrary values can be
converted into a binary string and be determined
at a later time again. For example a binary
string can be written into a file or into
the MS-Windows Clipboard and read at a later
time again.
The following table lists all accesses and
methods of the class bStream:
|
Read() |
Reads
the next value from the binary string
and returns it. |
|
Size
|
The
length of the binary string. |
|
Stream |
The
binary string. |
|
Write() |
Convert
a value to the binary string. |
The following code fragment converts several
different values in a binary string and writes
these in a file.
|
LOCAL auValue AS ARRAY
LOCAL oStream AS bStream
LOCAL hFile AS
PTR
// define several different values
auValue := {;
1,;
1.2345,;
"Hello",;
Today(),;
TRUE,;
{"Hello",
"how", "are", "you?",
42},;
NULL_OBJECT;
}
// convert array to binary string
oStream := bStream{}
IF oStream:Write(auValue)
// write binary string to
file
hFile := FCreate("c:\Stream.txt")
FWrite(hFile, oStream:Stream,
oStream:Size)
FClose(hFile)
ENDIF |
The following code fragment reads a binary
string from a file and determines the individual
values from binary string.
|
LOCAL uValue AS
USUAL
LOCAL oStream AS bStream
LOCAL cStream AS STRING
LOCAL iSize AS
INT
LOCAL hFile AS
PTR
IF File("c:\Stream.txt")
// reads binary string from
file
hFile := FOpen("c:\Stream.txt")
iSize := FSeek(hFile, 0,
FS_END)
FSeek(hFile, 0, FS_SET)
cStream := FReadStr(hFile,
iSize)
FClose(hFile)
// determines the values
from binary string
oStream := bStream{cStream}
uValue := oStream:Read()
ENDIF |
The class bStream supports the following data
types:
|
String |
|
Psz |
|
Symbol |
|
Logic |
|
Date |
|
Byte |
|
ShortInt |
|
LongInt |
|
Word |
|
DWord |
|
Float |
|
Real4 |
|
Real8 |
|
Array |
|
Object |
Values of the data type Object only can be
converted if the methods StreamIn() and StreamOut()
are defined in the appropriate class. The
following code fragment demonstrates the implementation
of the two methods for the VO class Point:
|
METHOD
StreamOut(oStream) CLASS Point
// write all relevant class
variables to the bStream object.
oStream:Write(self:X)
oStream:Write(self:Y)
RETURN TRUE
METHOD StreamIn(oStream) CLASS Point
// read all relevant class
variables from the bStream object
self:X := oStream:Read()
self:Y := oStream:Read()
RETURN TRUE |
Referring to the previous code fragment the
next code fragment converts an object of the
VO class Point to a binary string:
|
LOCAL oPoint AS
Point
// create object of class Point
oPoint := Point{1, 2}
// convert Point object into bStream
oStream := bStream{}
oStream:Write(oPoint) |
|
|
|
|
|
|