'testDLL 中的代码
'================================================
Option Explicit
Private strT As String
Private myT As Variant
Private myP As StdPicture
Private P As StdPicture
Public Property Get myTest() As String
myTest = strT
PropertyChanged "myTest"
End Property
Public Property Let myTest(newTest As String)
strT = newTest
PropertyChanged "myTest"
End Property
Public Property Let loadP(newP As StdPicture)
Set P = newP
PropertyChanged "loadP"
End Property
Public Property Get loadP() As StdPicture
Set loadP = P
PropertyChanged "loadP"
End Property
Private Sub Class_ReadProperties(PropBag As PropertyBag)
myTest = PropBag.ReadProperty("myTest", myT)
loadP = PropBag.ReadProperty("loadP", myP)
End Sub
Private Sub Class_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "myTest", myTest, myT
PropBag.WriteProperty "loadP", loadP, myP
End Sub
'================================================
'工程1中的代码
'================================================
Option Explicit
Public objT As testDLL.class1
Private pb As PropertyBag
Private p As StdPicture
Private Sub Command1_Click()
objT.myTest = Text1.Text
Set p = LoadPicture(VB.App.Path & "/10.jpg")
objT.loadP = p
End Sub
Private Sub Command2_Click()
On Error Resume Next
Dim varTemp As Variant
Dim F As Long
' PropertyBag 对象的实例化。
Set pb = New PropertyBag
' 使用 WriteProperty 将对象保存在 PropertyBag 中。
pb.WriteProperty "MyObj", objT
' 将 PropertyBag 的内容赋予一个 Variant。
varTemp = pb.Contents
' 将其保存到一个文本文件中。
F = FreeFile
Open "D:/objT.txt" For Binary As #F
Put #F, , varTemp
Close #F
End Sub
Private Sub Command3_Click()
On Error Resume Next
Image1.Picture = p
MsgBox objT.myTest
End Sub
Private Sub Form_Load()
Set objT = New testDLL.class1
Set pb = New PropertyBag
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objT = Nothing
Set pb = Nothing
End Sub
'================================================
'工程2中的代码
'================================================
Option Explicit
Private objT As testDLL.Class1
Private pb As PropertyBag
Private Sub Command1_Click()
'On Error Resume Next
Dim varTemp As Variant
Dim byteArr() As Byte
Dim F As Long
' PropertyBag 对象的实例化。
Set pb = New PropertyBag
' 将文件的内容读入一个 Variant 中。
F = FreeFile
Open "D:/objT.txt" For Binary As #F
Get #F, , varTemp
Close #F
' 将 Variant 赋值到一个 Byte 数组中。
byteArr = varTemp
' 赋予 PropertyBag Contents 属性。
pb.Contents = byteArr
' 使用 PropertyBag 进行对象实例化。
Set objT = pb.ReadProperty("MyObj")
End Sub
Private Sub Command2_Click()
On Error Resume Next
Image1.Picture = objT.loadP
MsgBox objT.myTest
End Sub
Private Sub Form_Load()
Set pb = New PropertyBag
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objT = Nothing
Set pb = Nothing
End Sub
'================================================
'================================================
Option Explicit
Private strT As String
Private myT As Variant
Private myP As StdPicture
Private P As StdPicture
Public Property Get myTest() As String
myTest = strT
PropertyChanged "myTest"
End Property
Public Property Let myTest(newTest As String)
strT = newTest
PropertyChanged "myTest"
End Property
Public Property Let loadP(newP As StdPicture)
Set P = newP
PropertyChanged "loadP"
End Property
Public Property Get loadP() As StdPicture
Set loadP = P
PropertyChanged "loadP"
End Property
Private Sub Class_ReadProperties(PropBag As PropertyBag)
myTest = PropBag.ReadProperty("myTest", myT)
loadP = PropBag.ReadProperty("loadP", myP)
End Sub
Private Sub Class_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "myTest", myTest, myT
PropBag.WriteProperty "loadP", loadP, myP
End Sub
'================================================
'工程1中的代码
'================================================
Option Explicit
Public objT As testDLL.class1
Private pb As PropertyBag
Private p As StdPicture
Private Sub Command1_Click()
objT.myTest = Text1.Text
Set p = LoadPicture(VB.App.Path & "/10.jpg")
objT.loadP = p
End Sub
Private Sub Command2_Click()
On Error Resume Next
Dim varTemp As Variant
Dim F As Long
' PropertyBag 对象的实例化。
Set pb = New PropertyBag
' 使用 WriteProperty 将对象保存在 PropertyBag 中。
pb.WriteProperty "MyObj", objT
' 将 PropertyBag 的内容赋予一个 Variant。
varTemp = pb.Contents
' 将其保存到一个文本文件中。
F = FreeFile
Open "D:/objT.txt" For Binary As #F
Put #F, , varTemp
Close #F
End Sub
Private Sub Command3_Click()
On Error Resume Next
Image1.Picture = p
MsgBox objT.myTest
End Sub
Private Sub Form_Load()
Set objT = New testDLL.class1
Set pb = New PropertyBag
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objT = Nothing
Set pb = Nothing
End Sub
'================================================
'工程2中的代码
'================================================
Option Explicit
Private objT As testDLL.Class1
Private pb As PropertyBag
Private Sub Command1_Click()
'On Error Resume Next
Dim varTemp As Variant
Dim byteArr() As Byte
Dim F As Long
' PropertyBag 对象的实例化。
Set pb = New PropertyBag
' 将文件的内容读入一个 Variant 中。
F = FreeFile
Open "D:/objT.txt" For Binary As #F
Get #F, , varTemp
Close #F
' 将 Variant 赋值到一个 Byte 数组中。
byteArr = varTemp
' 赋予 PropertyBag Contents 属性。
pb.Contents = byteArr
' 使用 PropertyBag 进行对象实例化。
Set objT = pb.ReadProperty("MyObj")
End Sub
Private Sub Command2_Click()
On Error Resume Next
Image1.Picture = objT.loadP
MsgBox objT.myTest
End Sub
Private Sub Form_Load()
Set pb = New PropertyBag
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objT = Nothing
Set pb = Nothing
End Sub
'================================================