主要内容

COM对象属性

MATLAB功能s for Object Properties

You can get the value of a property and, sometimes, change the value. You also can add custom properties.

Property names are not case-sensitive. You can abbreviate them as long as the name is unambiguous.

功能 Description

get

List one or more properties and their values.

set

Set the value of one or more properties.

isprop

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

addproperty

Add a custom property to a COM object.

deleteproperty

Remove a custom property from a COM object.

inspect

Open the Property Inspector to display and modify property values.

propedit

Display the built-in property page of the control, if any.

Work with Multiple Objects

You can use thegetset通过创建对象句柄的向量并在向量上使用这些命令来在多个对象上函数。要获取或设置多个对象的值,请使用功能形式getsetfunctions. Use dot notation, for exampleH.Propname., on scalar objects only.

Enumerated Values for Properties

Enumeration makes examining and changing properties easier because each possible value for the property is assigned text to represent it. For example, one of the values for theDefaultSaveFormatproperty in aMicrosoft®Excel®spreadsheet isxlUnicodeText. This text is easier to remember than a numeric value like 57.

Property Inspector

The Property Inspector enables you to access the properties of COM objects. To open the Property Inspector, use theinspectfunction from the MATLAB®command line or double-click the object in the MATLAB Workspace browser.

例如,创建Excel对象。然后设置DefaultFilePathproperty to an existing folder,C:\ExcelWork.

h = actxserver('Excel.Application'); h.DefaultFilePath ='C:\ExcelWork';

Display the properties of the object.

inspect(h)

Scroll down until you see theDefaultFilePath财产,你只是改变了,C:\ExcelWork.

Using the Property Inspector, changeDefaultFilePathonce more, this time to another existing folder,MyWorkDirectory. To do this, select the value at the right and type the new value.

Now go back to the MATLAB Command Window and confirm that theDefaultFilePathproperty has changed as expected.

h.DefaultFilePath
ans = C:\MyWorkDirectory

Note

If you modify properties at the MATLAB command line, refresh the Property Inspector window to see the change reflected there. Refresh the Property Inspector window by reinvoking theinspectfunction on the object.

Enumerated Values

A list button next to a property value indicates that the property accepts enumerated values. To see the values, click anywhere in the field on the right. For example, theCursorproperty has four enumerated values. The current valuexlDefault显示在属性名称旁边的字段中。

To change the value, use the list button to display the options for that property, and then click the desired value.

Custom Properties

You can add your own properties to an instance of a control using theaddpropertyfunction.

To remove custom properties from a control, use thedeletepropertyfunction.

Properties That Take Arguments

Some COM objects have properties that accept input arguments. Internally, MATLAB handles these properties as methods, which means you use themethods要么invokefunctions (not theget功能)查看属性。

Related Examples

More About