getObject 函数内部如何工作? [英] How getObject Function internally works?

查看:43
本文介绍了getObject 函数内部如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UFT 自动化 Inventor 2013,如下所示:-

I'm Automating Inventor 2013 using UFT as follows:-

Set oApp = GetObject(,"Inventor.Application")设置 oDoc = oApp.ActiveDocument

这里我使用 GetObject() 函数来获取运行 Inventor 应用程序的参考.但我有一个关于 GetObject() 函数的问题

Here I'm using GetObject() function to get reference of running Inventor Application. but I have a questions about GetObject() function that

1)它如何发现任何应用程序存在或处于运行状态?

1)How it find out any application is present or in running state?

2)它如何访问特定应用程序的头类,以便我们访问该应用程序类的所有方法和属性?

2)How it access header class of particular application so we will access of all methods and properties of that application's class?

有人能解释一下吗?

推荐答案

GetObjectCreateObject 是一部分VBScript 提供的 COM 自动化.VBScript 不能使用所有可通过 Windows 获得的 COM 对象.VBScript 只能使用那些公开称为编程标识符 (ProgID) 的字符串的对象.尽管并非所有 COM 对象都有 ProgID,但所有 COM 对象都有一个 128 位数字,称为类标识符或 CLSID.如果 COM 对象具有 ProgID,则可以使用 VBScript 来实例化该对象、调用其方法和属性并销毁该对象.

GetObject and CreateObject are part of COM automation provided by VBScript. VBScript can't use all the COM objects available through Windows. VBScript can use only those objects that expose a string called a programmatic identifier (ProgID). Although not all COM objects have a ProgID, all COM objects have a 128-bit number called a class identifier, or CLSID. If a COM object has a ProgID, you can use VBScript to instantiate the object, invoke its methods and properties, and destroy the object.

GetObjectCreateObject 的工作方式类似,但它们的用途不同.
如果需要创建对象的新实例,请使用 CreateObject.
如果需要引用对象的现有实例,请使用 GetObject.

GetObject and CreateObject works similar in a way, but they serve different purposes.
If you need to create a new instance of an object, use CreateObject.
If you need to reference an existing instance of an object, use GetObject.

GetObject 函数有两个可选参数:对象的路径名(即完整路径和文件名)和 对象的程序 ID.尽管这两个参数都是可选的,但您必须至少指定一个.如果省略这两个参数,则会导致错误.例如:

GetObject function has two optional arguments: the object's pathname (i.e., a full path and a filename) and the object's ProgID. Although both arguments are optional, you must specify at least one. If you omit both arguments, an error results. For example:

Dim wordDoc
Set wordDoc = GetObject ("FilePath\FileName.doc")

执行此代码时,将启动与指定路径名关联的应用程序并激活指定文件中的对象.如果路径名是零长度字符串 (""),则 GetObject 返回指定类型的新对象实例.如果省略路径名参数,GetObject 返回指定类型的当前活动对象.如果不存在指定类型的对象,则会发生错误.

When this code is executed, the application associated with the specified pathname is started and the object in the specified file is activated. If pathname is a zero-length string (""), GetObject returns a new object instance of the specified type. If the pathname argument is omitted, GetObject returns a currently active object of the specified type. If no object of the specified type exists, an error occurs.

如果您指定 ProgID 而不是路径名,结果会因您设置参数的方式而异.如果在代码中传递一个空字符串作为第一个参数,例如

If you specify the ProgID but not the pathname, the results differ depending on how you set up the arguments. If you pass an empty string as the first argument in code such as

Set wordApp = GetObject("", "Word.Application")

VBScript 返回 Word 应用程序对象的新实例(即代表 Word 应用程序的对象).这个 GetObject 调用相当于 CreateObject 调用

VBScript returns a new instance of Word's Application object (i.e., an object that represents the Word application). This GetObject call is equivalent to the CreateObject call

Set wordApp = CreateObject ("Word.Application")

如果省略路径名参数但保留逗号

If you omit the pathname argument but leave the comma

Set wordApp = GetObject (, "Word.Application")

VBScript 返回 Application 对象的现有实例(如果存在).

VBScript returns an existing instance of the Application object if one exists.

有关详细信息,请查看thisthis 链接.

For more information, check this and this links.

这篇关于getObject 函数内部如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆