Share via


COM Class

The COM class is use to create Component Object Model (COM) objects.

Syntax

class COM

Run On

Called

Methods

  Method Description
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 that it was associated with.
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 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 class.
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 that can be attached to the COM class and optionally 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 object 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

The COM class also supports Distributed Component Object Model (DCOM). DCOM enables objects that support DCOM to run on remote computers.

When a COM object has been instantiated by using 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 enables methods and properties to be directly called on the COM object, even though they don't appear in the Lookup list (for example, 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. If optional arguments are omitted, the COM object uses its default values. To omit an argument for the COM object and force it to use its default value, specify the COMArgument::NoValue enumeration, as shown in the following example.

com.comMethod(COMArgument::NoValue, "Hello Another World");

If the arguments to omit from the COM object appear 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 if 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 class by using the date and time properties. If the date return value is assigned to a date variable instead of a COMVariant class, the time component of the date is lost.

When the extended syntax is used, you can still call the COM class methods (the methods 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 (for example, attach), you cannot call that method on the COM object. To enable Microsoft Dynamics AX to call the method on the COM object instead of the method that has the same name on the COM class, prefix the duplicate method name with an underscore (for example, com._detach();).

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

Examples

This example calls the GetFileName method from the 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(); 
}

Inheritance Hierarchy

Object Class
  COM Class
    SysCOM Class

See Also

COMDispFunction Class

COMVariant Class