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 theget
function. 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 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 theOrganizationName
property, the same value returned by theget
function.
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_Application
objects.
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 theevents
function to list all events known to the server and use theeventlisteners
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
Aninterfaceis a set of related functions used to access the data of a COM object. When you create a COM object using theactxserver
function, MATLAB returns a handle to an interface. Use theget
andinterfaces
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
探讨Workbooks
interface, create a workbooks object and use the relevant MATLAB commands.
w = e.Workbooks;
Identify Objects and Interfaces
Function | Description |
---|---|
Return the class of an object. |
|
Determine if an object is of a given MATLAB class. |
|
Determine if the input is a COM object. |
|
Determine if an item is an event of a COM object. |
|
Determine if an item is a method of a COM object. |
|
Determine if an item is a property of a COM object. |
|
Determine if the input is a COM interface. |
See Also
get
|Property Inspector|events
|eventlisteners
|methodsview