The GetObject function returns a reference to a server-side COM object from a file.
Syntax | |||||
GetObject([PathName [, Class]]) | |||||
Return value | |||||
Type |
Description | ||||
Variant |
Reference to a COM object | ||||
Parameter | |||||
Use |
Name |
Type |
Passing |
Description | |
Optional |
Path |
String |
ByVal |
See below | |
Optional |
Class |
String |
ByVal |
See below | |
The optional Path parameter specifies the full path and name of the file that contains the object to retrieve. If Path is not specified, the parameter Class must be passed.
The optional Class parameter specifies the class of the object. Class uses the following syntax: AnwName.ObjektType
AnwName Name of the application that provides the object.
ObjektType Type or class of the object to be created.
Note
Use the GetObject function to access an ActiveX object from a file and assign the returned object to an object variable.
Example
Dim CADObjekt As Variant
CADObjekt := Server.GetObject("C:\CAD\SCHEMA.CAD")
If this code is executed the application connected with the specified PathName is started and the object in the specified file is activated.
If PathName is a zero string ("), GetObject returns a new instance of the object from the specified type. If the PathName argument is not specified, GetObject returns a currently active object from the specified type. If no object of the specified type exists, an error occurs.
Some applications allow you to activate part of a file. Add an exclamation point (! ) at the end of the file name, followed by the string indicating the part of the file to activate. For more information about how to create this string see the documentation for the application that created the object.
For example, in a graphics application, you have multiple layers of a drawing that are stored in a file. You can use the following code to activate a layer within a drawing called SCHEMA.CAD:
SchichtObjekt := Server.GetObject("C:\CAD\SCHEMA.CAD!Layer3")
If you do not specify the class argument of the object, automation determines which application to start and the object to activate, based on the file name provided. However, some files can support more than one class of an object. For example, a drawing can support three different object types: an Application object, a Drawing object, and a Toolbar object, all of which are part of the same file. Use the optional class argument to specify which object in the file you want to activate. Example:
Dim MeinObjekt As Variant
MeinObjekt := Server.GetObject("C:\DRAWINGS\BEISPIEL.DRW", "FIGMENT.DRAWING")
In the example above, FIGMENT is the name of a graphics application and DRAWING is one of the supported object types.
If an object has been activated, refer to it in the code using the defined object variables. In the following example, you access properties and methods of the new object from the MyObject object variable. Example:
MeinObjekt.Line(9, 90)
MeinObjekt.InsertText(9, 100, "Hallo !")
MeinObjekt.SaveAs("C:\ENTWURF\BEISPIEL.DRW")
Note
Use the GetObject function if a current instance of the object exists or if you want to create the object with an existing file. If no current instance exists and you do not want to start the object with an existing file use the CreateObject function.
If an object has registered itself as an object with only one instance (SingleValue in VB), only one instance of the object is created, regardless of how often CreateObject is executed. For an object with only one instance, GetObject always returns the same instance if a call is made with a zero string (""). An error occurs if the PathName argument is not specified.