Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

vbscript - How getObject Function internally works?

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

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

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

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

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

can anybody explain this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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 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 ("FilePathFileName.doc")

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.

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 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 returns an existing instance of the Application object if one exists.

For more information, check this and this links.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...