Contents

Explore COM Objects

About Your Object

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.

Exploring Properties

A property is information that is associated with a COM object. This topic shows you how to look at the properties of your object. For detailed information on reading and setting property values, see Use Object Properties.

To see a list of all properties of an object, you can use the COM get function or the Property Inspector, a GUI provided by MATLAB to display and modify properties.

In this section, we explore a Microsoft® Excel® object. To begin, create the object myApp:

myApp = actxserver('Excel.Application');

Listing Properties

The get function lists all properties. For example, from the MATLAB command prompt, type:

get(myApp)

MATLAB displays information like the following:

     Application: [1x1 Interface.Microsoft_Excel_9.0_
 Object_Library._Application]
         Creator: 'xlCreatorCode'
          Parent: [1x1 Interface.Microsoft_Excel_9.0_
 Object_Library._Application]
      ActiveCell: []
     ActiveChart: [1x50 char]
                :
 OperatingSystem: 'Windows (32-bit) NT 5.01'
OrganizationName: 'The MathWorks'
                :

One property is OrganizationName; its value in this example is The MathWorks.

Using the Property Inspector

The Property Inspector opens a new window showing the object's properties. This topic explains how to open it. For detailed information, see Using the Property Inspector.

You can open the Property Inspector using either of these methods:

  • Call the inspect function from the MATLAB command line.

  • Double-click the object in the MATLAB Workspace browser.

For example, type:

inspect(myApp)

The Inspector window opens. Scroll down until you see the OrganizationName property. It should be the same value the get function returned; in this case, The MathWorks.

Exploring Methods

A method is a procedure you call to perform a specific action on the COM object. This topic shows you how to identify methods belonging to your object. For detailed information, see Use Methods.

To see a list of all methods supported by the Excel object, type:

methodsview(myApp)

MATLAB opens a window showing the method signatures for COM.Excel_Application objects. For detailed information about Excel objects, see documentation on the MSDN® website. The documentation for Microsoft Office 2010 is at Excel Object Model Reference.

Exploring 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, a user clicking the mouse at a particular location in a server interface window might require the client to take some action in response. 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.

This topic shows you how to identify events available to your object. For detailed information, see Use Events. For information on event handlers, see Writing Event Handlers.

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

In this section, we use the Microsoft Internet Explorer® Web browser. To begin, create the object myNet:

myNet = actxserver('internetexplorer.application');

Listing Server Events

Type:

events(myNet)

MATLAB displays event information like:

        :
StatusTextChange = void StatusTextChange(string Text)
ProgressChange = void ProgressChange(int32 Progress,int32 ProgressMax)
CommandStateChange = void CommandStateChange(int32 Command,bool Enable)
        :  

Listing Registered Events

No events are registered now.

eventlisteners(myNet)
ans = 
      {}

Exploring Interfaces

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

In this section, we explore an Excel object. To begin, create the object e:

e = actxserver('Excel.Application');

Additional Interfaces

Components often provide more interfaces, based on IDispatch. To see these interfaces, type:

get(e)

MATLAB displays information like:

    Application: [1x1 Interface.Microsoft_Excel_11.0_Object_Library._Application]
        Creator: 'xlCreatorCode'
         Parent: [1x1 Interface.Microsoft_Excel_11.0_Object_Library._Application]
     ActiveCell: []
    ActiveChart: [1x50 char]
               :
      Workbooks: [1x1  Interface.Microsoft_Excel_11.0_Object_Library.Workbooks]
               :

In this example, Workbooks is an interface. To explore the Workbooks interface, type:

w = e.Workbooks;

To see its properties, type:

get(w)
    Application: [1x1 Interface.Microsoft_Excel_11.0_Object_Library._Application]
        Creator: 'xlCreatorCode'
         Parent: [1x1 Interface.Microsoft_Excel_11.0_Object_Library._Application]
          Count: 0

To see its methods, type:

invoke(w)
	Add = handle Add(handle, Variant(Optional))
	Close = void Close(handle)
	Item = handle Item(handle, Variant)
	Open = handle Open(handle, string, Variant(Optional))
	OpenText = void OpenText(handle, string, Variant(Optional))
	OpenDatabase = handle OpenDatabase(handle, string, Variant(Optional))
	CheckOut = void CheckOut(handle, string)
	CanCheckOut = bool CanCheckOut(handle, string)
	OpenXML = handle OpenXML(handle, string, Variant(Optional))

Identifying Objects and Interfaces

You can get more information about a control or server using the following functions.

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 or ActiveX® 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

This example creates a COM object in an Automation server running the Excel application, giving it the handle e, and a Workbooks interface to the object, with handle w.

e = actxserver('Excel.Application');
w = e.Workbooks;

To see if e is a handle to a COM object, type:

iscom(e)
ans =
     1

To test e against a known class name, type:

isa(e,'COM.excel_application')
ans =
     1

To see if w is a handle to a COM interface, type:

isinterface(w)
ans =
     1

To find out the class of variable w, type:

class(w)
ans =
   Interface.Microsoft_Excel_11.0_Object_Library.Workbooks

To see if UsableWidth is a property of e, type:

isprop(e,'UsableWidth')
ans =
     1

To see if SaveWorkspace is a method of e, type:

ismethod(e,'SaveWorkspace')
ans =
     1

See Also

| | | |

Was this topic helpful?