_read
Public Sub _read ( Stream As Stream )
READ 指令调用
_read
方法来取消对对象的序列化。
READ 指令将首先初始化对象,然后调用对象上的
_read
方法。
只有当可以在没有参数的情况下调用
_new 构造函数时,这才会起作用。
该方法将目标流作为参数,并且必须读取该流才能初始化新创建的对象。
此方法不返回任何结果。
Examples
Dim Item1 As New MyClass
Item1.abc = 123
Item1.def = "456"
Print "In: " & Item1.abc & "-" & Item1.def
Dim f1 As File
f1 = Open "~/item.bin" For Write Create
Write #f1, Item1 As Object 'MyClass
Close f1
Shell "hexdump -C ~/item.bin"
Dim f2 As File
f2 = Open "~/item.bin" For Read
Dim Item2 As MyClass = Read #f2 As MyClass
Close f2
Print "Out: " & Item2.abc & "-" & Item2.def
Class MyClass
Public abc As Integer
Public def As String
Public Sub _read(f As Stream)
abc = Read #f As Integer
def = Read #f As String
End
Public Sub _write(f As Stream)
Write #f, abc As Integer
Write #f, def As String
End
End Class
00000000 6f 07 4d 79 43 6c 61 73 73 7b 00 00 00 03 34 35 |o.MyClass{....45|
00000010 36 |6|
00000011
In: 123-456
Out: 123-456
See also