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

Apropertyis information that is associated with a COM object. To see a list of properties of an object, use thegetfunction. Alternatively, use the MATLAB Property Inspector, a user interface to display and modify properties. For example, to list all properties of aMicrosoft®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 theinspectfunction from the MATLAB command line:

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

Scroll down until you see theOrganizationNameproperty, the same value returned by thegetfunction.

Methods

Amethod是一个过程调用来执行特定的活动吗on 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 forCOM.Excel_Applicationobjects.

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

Events

Aneventis 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 isfired, the server communicates this occurrence to the client. If the client islisteningfor this particular type of event, it responds by executing a routine called anevent handler.

Use theeventsfunction to list all events known to the server and use theeventlistenersfunction 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

Aninterfaceis a set of related functions used to access the data of a COM object. When you create a COM object using theactxserverfunction, MATLAB returns a handle to an interface. Use thegetandinterfacesfunctions 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,Workbooksis an interface.

e.Workbooks
ans = Interface.000208DB_0000_0000_C000_000000000046

探讨Workbooksinterface, create a workbooks object and use the relevant MATLAB commands.

w = e.Workbooks;

Identify Objects and Interfaces

Function Description

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

External Websites