我在 Option Strict 开启时出现从二进制文件读取结构数据的功能有问题。
Public Function arh_setup(ByVal rw As Boolean) As Integer Dim retval As Integer = 0 Dim fnum As Integer = FreeFile() Dim temp As ValueType = CType(New aSetup, ValueType)
Try
FileOpen(fnum, setup_file, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Shared, Len(asT))
If rw Then
FilePut(fnum, asT, 1)
Else
FileGet(fnum, temp, 1)
End If
FileClose(fnum)
Catch ex As Exception
retval = -1
End Try
' Now is question here
' How to get data from temp to asT??
EDIT:
Solution is asT = CType(temp, aSetup)
temp= Nothing
Return retval
End Function
asT 是全局声明的 aSetup (结构)类型的变量,它应该从包含(正确)读取数据的 temp 中获取数据。
问题是如何将数据从局部临时变量复制到全局 asT 变量,最好不循环(逐字节)或在不可能的情况下循环?