Axaptapedia is now maintained by AgileCadence For more information please click here.

COM

From Axaptapedia
Revision as of 04:33, 4 February 2008 by MaxBelugin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

COM stands for Component Object Model and lets application expose its object for other applications.

Axapta can use other Application objects via COM class or ActiveX control (download small small demo File:Test OWC.zip). Other application can use axapta through COM with Axapta Business Connector (see developer's documentation)

For ease of use you can generate wrapper for the com type library: Main Menu\Tools\Development toolz\Wizard\COM class wizard

Look in the AOT for documentation of the following classes:

  • \System Documentation\Classes\COM
  • \System Documentation\Classes\COMDispFunction
  • \System Documentation\Classes\COMEnum2Object
  • \System Documentation\Classes\COMEnum2Variant
  • \System Documentation\Classes\COMError
  • \System Documentation\Classes\COMVariant

Mapping COM classes to the axapta classes[edit]

These classes map COM (more properly automation objects) to the Axapta objects using the following rules:

  • methods are methods of axapta

<xpp>

 x.test('1')

</xpp> becomes <xpp>

 x.test('1')

</xpp>

  • properties are methods of axapta

<xpp>

 x.test='1'

</xpp> becomes <xpp>

 x.test('1')

</xpp>

  • collections are properties which return collection objects

<xpp>

 y=x.test(1) 

</xpp> becomes <xpp>

 Com collection=x.test();
 Com y=collection.Item(1);

</xpp>

  • you can not call methods of return values of other methods directly. Use intermediate variable instead to help Axapta to detect return value types (by the way, if you use Object class you must do the same way)

<xpp>

 x.test.test

</xpp> becomes <xpp>

 Com y=x.test();
 y.test();

</xpp>

Handling COM errors[edit]

<xpp> void setInfo() {

   COMError errorCom;
       try
       {
            object.SetInfo();
       }
       catch (Exception::Error)
       {
           errorCom = object.error();
           if (errorCom)
               throw error(strFmt("Error %1 ('%2')",
                   errorCom.number(), WinApi::formatMessage(errorCom.number())));
           else
               throw Exception::Error;
       }

} </xpp>