精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● VB和Basic>>〓〓..技术文章连载..〓〓>>ActiveX>>ACTIVEX(5)

主题:ACTIVEX(5)
发信人: antfeeling()
整理人: fishy(2000-08-22 08:08:48), 站内信件
创建和测试 Thing 对象


要测试一个类,例如本例中的 Thing 类,测试工程必须请求部件创建该类的一个
对象。

注意 创建一个 ActiveX DLL 示例需要分为几步,这个帮助主题只是其中一步。
要访问该帮助主题,选择帮助主题“创建 ActiveX DLL”即可。

在测试工程中调整 Form1 的大小,然后象图 2.2 那样在上面放五个命令按钮和
一个复选框。如果您从来没有用 Visual Basic 创建过窗体,请参阅《Visual B
asic 程序员指南》中的“用 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

在“对象”框中,选择“Command1”。在 Click 事件过程中添加以下代码: 
'按钮“Create New Thing”。
Private Sub Command1_Click()
Set mthTest = New Thing
mthTest.Name = _
InputBox("Enter a name for the Thing", _
"Test Thing")
End Sub

用类似的办法,在 Command2、Command3 和 Command4 的 Click 事件过程添加以
下代码: 
'按钮“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 



--
※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 61.141.204.217]

[关闭][返回]