~.qTp.~ 好久不见~~~ Hey dude @ Long time no see ·^o^·

QTP中的.NET技术--DotNetFactory

上一篇 / 下一篇  2010-11-08 10:23:19 / 个人分类:.qTp. 为卿加冕

Description
  Enables you to create an instance of a .NET object, and access its methods and properties.

Important Information
You can use this object to access the static methods and properties of a class that does not have an instance constructor, for example, System.Environment, as well as a class that does.

Associated Method
  CreateInstance Method

Description
Returns a COM interface for a .NET object.

Important Information
If you want to use a .NET object as an argument for a method in QuickTest, you must first create a COM interface for the .NET object using the CreateInstance method. Then you pass that interface as the method argument.

Syntax
Set var_CreateInstance = DotNetFactory.CreateInstance (TypeName [,Assembly] [,args])


 
TypeName(String) 

The full name of the object type, for example,System.Windows.Forms.Form. 


Assembly(Any) 

Optional. If the assembly is preloaded in the registry, you do not need to enter it. Otherwise, you should enter the full path name, for example,System.Windows.Forms. If you want to create an instance of a type in the GAC (Global Assembly Cache), you can enter the short name, for example,Forms.
Note:If you do not pass this argument, QuickTest assumes that the assembly is resident in memory. If QuickTest does not find the assembly, an error message is displayed during the run session. 

args(Any)

Optional. The required arguments, if any, for the specified TypeName and/or Assembly. 


Example
The following example uses the CreateInstance method to create an instance of a blank Windows form. object, display the form. on screen, and then close it after two seconds.

Set var_CreateInstance = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")

var_CreateInstance.Show

wait 2

var_CreateInstance.Close

The following example uses the CreateInstance method to create an instance of a system  environment object, and to display a message box listing the current directory. In this example, there is no need to specify the optional arguments because the required assembly is already in memory.

 Set var_CreateInstance = DotNetFactory.CreateInstance("System.Environment")
 msgbox var_CreateInstance.CurrentDirectory

Return Value
 A Variant value. Returns the defined instance of the .NET object.


TAG:

hanjj的个人空间 引用 删除 hanjj   /   2010-11-10 09:28:06
你的资料很好.但是,是否可以多给出一些具体的例子.在测试中可以应用的.
 

评分:0

我来说两句

Open Toolbar