Main Content

Explore COM Objects

A COM object has properties, methods, events, and interfaces. Your vendor documentation describes these features, but you can also learn about your object using MATLAB® commands.

Properties

A property is information that is associated with a COM object. To see a list of properties of an object, use the get function. Alternatively, use the MATLAB Property Inspector, a user interface to display and modify properties. For example, to list all properties of a Microsoft® Excel® object type the following command. MATLAB displays the properties for your Excel version.

myApp = actxserver('Excel.Application');
get(myApp)

To display a single property, type the following. MATLAB displays the value for your application.

myApp.OrganizationName
ans =

MathWorks, Inc.

To open the Property Inspector, choose one of the following. MATLAB opens the Inspector window.

  • Call the inspect function from the MATLAB command line:

    inspect(myApp)
  • Double-click the myApp object in the MATLAB Workspace browser.

Scroll down until you see the OrganizationName property, the same value returned by the get function.

Methods

A method is a procedure you call to perform a specific action on the COM object. For example, to list all methods supported by the Excel object, type the following. MATLAB opens a window showing the method signatures for COM.Excel_Application objects.

myApp = actxserver('Excel.Application');
methodsview(myApp)

Events

An event is typically a user-initiated action that takes place in a server application, which often requires a reaction from the client. For example, clicking the mouse at a particular location in a server interface window might require the client to respond. When an event is fired, the server communicates this occurrence to the client. If the client is listening for this particular type of event, it responds by executing a routine called an event handler.

Use the events function to list all events known to the server and use the eventlisteners function to list registered events.

For example, to list the events for the Microsoft Internet Explorer® web browser, type the following. MATLAB displays the events for your Internet Explorer version.

myNet = actxserver('internetexplorer.application');
events(myNet)

To see which events have event handlers, type:

eventlisteners(myNet)
ans = 
      {}

An empty result means that no events are registered.

Interfaces

An interface is a set of related functions used to access the data of a COM object. When you create a COM object using the actxserver function, MATLAB returns a handle to an interface. Use the get and interfaces functions to see other interfaces implemented by your object.

For example, to see interfaces of an Excel object, type:

e = actxserver('Excel.Application');
get(e)

MATLAB displays the properties, including interfaces, for your Excel version. For example, Workbooks is an interface.

e.Workbooks
ans =
 
	Interface.000208DB_0000_0000_C000_000000000046

To explore the Workbooks interface, create a workbooks object and use the relevant MATLAB commands.

w = e.Workbooks;

Identify Objects and Interfaces

FunctionDescription

class

Return the class of an object.

isa

Determine if an object is of a given MATLAB class.

iscom

Determine if the input is a COM object.

isevent

Determine if an item is an event of a COM object.

ismethod

Determine if an item is a method of a COM object.

isprop

Determine if an item is a property of a COM object.

isinterface

Determine if the input is a COM interface.

See Also

| | | |

Related Topics