COM::getObject Method [AX 2012]
Returns an instance of a COM object that is running.
client server public static COM getObject(str className)
Run On
CalledParameters
- className
- Type: str
The ProgID value or class name of the COM object that is used to create the instance of the COM class.
Return Value
Type: COM ClassAn instance of the COM class for the class that is specified by the className parameter; nullNothingnullptrunita null reference (Nothing in Visual Basic) if the instance could not be created.
The following example shows how to retrieve an instance of a running COM object.
COM objExcel, objWorkBook, objWorkBooks;
InteropPermission perm;
// Set code access permission to help protect the use of COM.new.
perm = new InteropPermission(InteropKind::ComInterop);
perm.assert();
objExcel = COM::getObject("Excel.Application");
if (!objExcel)
{
// Unable to connect to a running instance of Microsoft Excel.
// Try starting it.
objExcel = new COM("Excel.Application");
if (!objExcel)
{
Info ("Unable to find or create an instance of Excel");
return; // Or other error action.
}
}
// Close code access permission scope.
CodeAccessPermission::revertAssert();
objExcel.visible(true);
objWorkBooks = objExcel.workbooks();
if (objWorkBooks)
{
objWorkBook = objWorkBooks.open("d:\\mydata\\book1.xls");
}
Show: