要测试一个类,例如本例中的 Thing 类,测试工程必须请求部件创建该类的一个对象。
注意 创建一个 ActiveX DLL 示例需要分为几步,这个帮助主题只是其中一步。要访问该帮助主题,选择帮助主题“创建 ActiveX DLL”即可。
在测试工程中调整 Form1 的大小,然后象图 2.2 那样在上面放五个命令按钮和一个复选框。如果您从来没有用 Visual Basic 创建过窗体,请参阅《Visual Basic 程序员指南》中的“用 Visual Basic 开发应用程序”。
图 2.2 用来测试 Thing 类的窗体
下表列出了需要设置的属性值。
对象 | 属性 | 设置 |
Form | Caption | Thing Demo |
Command1 | Caption | Create New Thing |
Command2 | Caption | Show the Thing |
Command3 | Caption | Reverse the Thing’s Name |
Command4 | Caption | Release the Thing |
Command5 | Caption | Temporary Thing |
Check1 | Caption | Stuck on itself |
要添加创建 Thing 并调用它的属性和方法的方法,请按照以下步骤执行:
Option Explicit '
对Thing
对象的引用。Private mthTest As Thing
'
按钮“Create New Thing
”。Private Sub Command1_Click()
Set mthTest = New Thing
mthTest.Name = _
InputBox("Enter a name for the Thing", _
"Test Thing")
End Sub
'
按钮“Show the Thing
”。Private Sub Command2_Click()
MsgBox "Name: " & mthTest.Name, , _
"Thing " & mthTest.DebugID
End Sub
'
按钮“Reverse the Thing's Name
”。Private Sub Command3_Click()
mthTest.ReverseName
'
通过设置值来单击“Show the Thing
”。Command2.Value = True
End Sub
'
按钮“Release the Thing
”。Private Sub Command4_Click()
Set mthTest = Nothing
End Sub
目前,暂时不需要添加 Command5 和复选框的代码。
创建 ActiveX DLL 示例需要好几步,该帮助主题只是其中一步。
目的 | 请参阅 |
到下一步 | 运行 TestThing 测试应用程序 |
从头开始 | 创建一个 ActiveX DLL |