Creating Properties

A property is a member function that sets or returns information about the state of the object, such as color or visibility. Most properties have a pair of accessor functions — a function to get the property value and a function to set the property value. Properties that are read-only or write-only, however, have only one accessor function.

Accessor Functions

The accessor functions for a single property have the same dispatch identifier (DISPID). The purpose of each function is indicated by attributes that are set for the function. These attributes are set in the .odl file description of the function, and are passed in the wFlags parameter to Invoke in order to set the context for the call. The attributes and flags are shown in the following table.

Purpose of function ODL attribute wFlags
Returns a value. propget DISPATCH_PROPERTYGET
Sets a value. propput DISPATCH_PROPERTYPUT
Sets a reference. propputref DISPATCH_PROPERTYPUTREF

The propget attribute designates the accessor function that gets the value of a property. When the ActiveX client needs to get the value of the property, it passes the DISPATCH_PROPERTYGET flag to Invoke.

The propput attribute designates the accessor function that sets the value of a property. When an ActiveX client needs to set a property by value, it passes the DISPATCH_PROPERTYPUT flag to Invoke. In Visual Basic, Let statements set properties by value.

The propputref attribute indicates that the property should be set by reference, rather than by value. In these cases, ActiveX clients that need to set a reference to a property pass DISPATCH_PROPERTYPUTREF. Visual Basic treats the Set statement as a by-reference property assignment.