• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

A more efficient way to test Visual Basic class interfaces

发布: 2007-6-21 21:57 | 作者:   | 来源:   | 查看: 14次 | 进入软件测试论坛讨论

领测软件测试网

   
  A more efficient way to test Visual Basic class interfaces

If you develop applications that use several versions of a component,
you might have read "Polymorphism, Interfaces, Type Libraries, and

GUIDs" in VB注释:s Help file.  Microsoft gives an example of how to test
whether an object supports a particular interface:

Dim fnr As FinanceRules
Dim ifin As IFinance
Dim ifin2 As IFinance2

On Error Resume Next
Set fnr = New FinanceRules
注释: (Error handling code omitted.)
注释: Attempt to access the preferred interface.
Set ifin2 = fnr
If Err.Number <> 0 ThenIf Err.Number <> 0 Then
   注释: Access the more limited interface.
   Set ifin = fnr
   注释: (Code to provide limited functionality,
   注释:   using the object variable ifin.)
Else
   注释: (Code to provide full functionality,
   注释:   using the object variable ifin2.)
End If

As you can see, this example uses inline error handling to determine
whether a type-mismatch error occurs when setting ifin2 = fnr.  If your
routine already has an active error handler, your code can become
cluttered with this solution--especially if you test for several
different interfaces in a single routine.

To make your code more readable, use:

On Error Goto YourErrorHandler
Set fnr = New FinanceRules
注释: (Errors produced by previous line are handled
注释:   in YourErrorHandler).

注释: Check to see if fnr supports the IFinance2 interface
If Not TypeOf fnr Is IFinance2 Then
   注释: Access the more limited interface.
   Set ifin = fnr
   注释: (Code to provide limited functionality,
   注释:  using the object variable ifin.)
Else
   set ifin2 = fnr
   注释: (Code to provide full functionality,
   注释:   using the object variable ifin2.)
End If

Note that you can注释:t use

If TypeName(fnr) <> "IFinance2" Then

because TypeName() always returns the actual class name of the
instantiated object, not the interfaces it implements.

This tip was contributed by Travis E. Hyatt.

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网