Skip to main content
  
COM Class [AX 2012]

This class is used to create Component Object Model (COM) objects.

Syntax
class COM

Run On

Called
Methods
 MethodDescription
Gg803455.pubmethod(en-us,AX.60).gif attach Attaches an instance of the COM class to a COM interface.
Gg803455.pubmethod(en-us,AX.60).gif cancelTimeOut Cancels a previous method call to the setTimeOut method. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif detach Detaches a COM object from the class with which it was associated.
Gg803455.protmethod(en-us,AX.60).gif dispatch Reserved. Do not explicitly call this method.
Gg803455.pubmethod(en-us,AX.60).gif documentationName Returns the textual name of the COM object that is associated with the instance of the COM class.
Gg803455.pubmethod(en-us,AX.60).gif equal Determines whether the specified object is equal to the current one. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif error Returns a COMError class object that is associated with the instance of the COM class.
Gg803455.pubmethod(en-us,AX.60).gif finalize Frees resources that are associated with the instance of the COM .
Gg803455.pubmethod(en-us,AX.60).gif getTimeOutTimerHandle Returns the timer handle for the object. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif handle Retrieves the handle of the class of the object. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif interface Returns the interface that is associated with the COM object.
Gg803455.pubmethod(en-us,AX.60).gif lcid
Gg803455.pubmethod(en-us,AX.60).gif new Creates an instance of the COM class to be attached to the COM class. Optionally, this method instantiates a COM object on a specified computer.
Gg803455.pubmethod(en-us,AX.60).gif notify Releases the hold on an object that has called the wait method on this object. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif notifyAll Releases a lock on the object that was issued by the wait method on this object. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif objectOnServer Determines whether the object is on a server. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif owner Returns the instance that owns the object. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif setTimeOut Sets up the scheduled execution of a specified method. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif toString Returns a string that represents the instance of the COM class.
Gg803455.pubmethod(en-us,AX.60).gif usageCount Returns the current number of references, that is, the value of the reference counter, that the object has. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif wait Pauses a process. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif xml Returns an XML string that represents the current object. (Inherited from Object.)
Gg803455.pubmethod(en-us,AX.60).gif Gg803455.static(en-us,AX.60).gif ::createFromInterface Creates an instance of the COM class by using the specified COM interface.
Gg803455.pubmethod(en-us,AX.60).gif Gg803455.static(en-us,AX.60).gif ::createFromObject Creates an instance of the COM class by using the specified COM object.
Gg803455.pubmethod(en-us,AX.60).gif Gg803455.static(en-us,AX.60).gif ::createFromVariant Creates an instance of the COM class by using the specified instance of the COMVariant class.
Gg803455.pubmethod(en-us,AX.60).gif Gg803455.static(en-us,AX.60).gif ::getObject Returns an instance of a COM object that is running.
Gg803455.pubmethod(en-us,AX.60).gif Gg803455.static(en-us,AX.60).gif ::getObjectEx Returns an instance of a COM class that is specified by its file name.
Gg803455.pubmethod(en-us,AX.60).gif Gg803455.static(en-us,AX.60).gif ::unsupported Reserved.
Top
Remarks

DCOM is also supported by the COM class. DCOM allows for objects that support DCOM to run on remote computers.

When a COM object has been instantiated with the COM class, its methods and properties can be accessed by using either the COMDispFunction class or the extended syntax for the COM class.

The extended syntax allows for methods and properties to be directly called on the COM object, even though they do not appear in the lookup list, such as com.comMethod("Hello World");. The extended syntax supports calls to methods and properties that take any number of arguments.

Some COM objects support the concept of optional arguments. Only optional variant arguments can be omitted. The COM object will then use its default value. To omit an argument for the COM object and force it to use its default value, specify the COMArgument::NoValue enumeration. This is shown in the following example. com.comMethod(COMArgument::NoValue, "Hello Another World"); If the arguments to omit from the COM object are those appearing at the end of the argument list, omit them from the code.

The following types are supported for the extended syntax for the COM class argument type and return type:

  • array

  • COM

  • COMVariant

  • date

  • enum

  • int

  • real

  • str

If a COM object returns a date and the extended syntax is used, the return value of the COM method should be assigned to a COMVariant class variable. The actual date and time (format) can then be extracted from the COMVariant by using the date and time method properties. If the date return value is assigned to a date variable instead of a COMVariant , the time component of the date is lost.

When the extended syntax is used, it is still possible to call the COM class methods, that is the ones that appear in the lookup list, on the objects. The COM class methods have a higher priority than the methods on the actual COM object.

If a method on the COM object has the same name as a method on the COM class, such as attach, call that method cannot be called on the COM object. For Microsoft Dynamics AX to call the method on the COM object instead of the method of the same name on the COM class, prefix the duplicate method name with an underscore, such as com._detach();.

The extended syntax for the COM class is evaluated at run time, not at compile time. This causes a small decrease in performance. If high-performance code is required, consider using the COMDispFunction class . It offers performance improvements compared with the extended syntax for the COM class.

Examples

This example calls the GetFileName method from Scripting.FileSystemObject COM object.

void COMExample() 
{ 
    COM               com; 
    str               result; 
    InteropPermission perm; 
    ; 
  
    // Set code access permission to help protect the use of the 
    // COM object. 
    perm = new InteropPermission(InteropKind::ComInterop); 
    if (perm == null) 
    { 
        return; 
    } 
    // Permission scope starts here. 
    perm.assert(); 
  
    com = new COM("Scripting.FileSystemObject"); 
    if (com != null) 
    { 
        result = com.GetFileName(@"c:\boot.ini"); 
    } 
  
    // Close code access permission scope. 
    CodeAccessPermission::revertAssert(); 
}