forked from cdhigh/Vb6Tkinter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clsSerialization.cls
135 lines (112 loc) · 3.19 KB
/
clsSerialization.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsSerialization"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
'对象持续化类
Private mInnerArray() As String
Private mInnerArrayItems As Long
Private mInnerArrayCur As Long
'设置要解码的字符串
Public Property Let SerialString(newStr As String)
ResetStrArray
mInnerArray = Split(newStr, vbCrLf)
mInnerArrayItems = UBound(mInnerArray) + 1
mInnerArrayCur = 0
End Property
Public Property Get SerialString() As String
If mInnerArrayItems > 0 Then
SerialString = Join(mInnerArray, vbCrLf)
Else
SerialString = ""
End If
End Property
Public Sub Serializer(ParamArray vObjs() As Variant)
Dim i As Long
For i = LBound(vObjs) To UBound(vObjs)
Dim tType As String
tType = GetType(vObjs(i))
SaveData tType 'Save Type
Select Case tType
Case "Object"
SaveData TypeName(vObjs(i))
vObjs(i).Serializer Me
Case "Variant"
'Data = TypeName(vObjs(i))
SaveData vObjs(i)
Case "Nothing"
'Do Nothing
End Select
Next i
End Sub
Public Sub Deserializer(ParamArray vObjs() As Variant)
Dim i As Long, tType As String
For i = LBound(vObjs) To UBound(vObjs)
Dim Classification As String
Classification = GetData()
Select Case Classification
Case "Object"
tType = GetData()
vObjs(i).Deserializer Me
Case "Variant"
vObjs(i) = GetData()
Case "Nothing"
End Select
Next i
End Sub
Private Function GetType(vObj As Variant) As String
If IsObject(vObj) = True Then
GetType = "Object"
Exit Function
End If
If TypeName(vObj) = "Nothing" Then
GetType = "Nothing"
Exit Function
End If
If GetType = "" Then
GetType = "Variant"
Exit Function
End If
End Function
Private Sub Class_Initialize()
ResetStrArray
End Sub
Private Sub Class_Terminate()
ResetStrArray
End Sub
Private Function GetData() As Variant
GetData = GetOneInnerString
End Function
Private Sub SaveData(vData As Variant)
AppendInnerString CStr(vData)
End Sub
Private Function GetOneInnerString() As String
If mInnerArrayCur < mInnerArrayItems Then
GetOneInnerString = mInnerArray(mInnerArrayCur)
mInnerArrayCur = mInnerArrayCur + 1
End If
End Function
Private Sub AppendInnerString(ByVal newStr As String)
ReDim Preserve mInnerArray(mInnerArrayItems) As String
mInnerArray(mInnerArrayItems) = newStr
mInnerArrayItems = mInnerArrayItems + 1
End Sub
Private Sub ResetStrArray()
mInnerArrayItems = 0
mInnerArrayCur = 0
Erase mInnerArray
End Sub
Public Sub Reset()
ResetStrArray
End Sub