次の方法で共有


defaultcollelem 属性

[defaultcollelem] 属性は、既定のコレクションの要素のアクセサー関数としてプロパティにフラグを設定します。

[property-attribute-list, defaultcollelem] return-type property-name(prop-param-list)

パラメーター

property-attribute-list

プロパティに適用されるその他の属性。

return-type

関数の戻り値の型を指定します。

property-name

プロパティの名前。

prop-param-list

プロパティに関連付けられている 0 個以上のパラメーターの一覧。

解説

[defaultcollelem] 属性は、Visual Basic® コードの最適化に使用されます。 インターフェイスまたはディスパッチインターフェイスのメンバーにアクセサー関数としてフラグが設定されている場合、呼び出しはそのメンバーに直接移動します。

プロパティに 対して [defaultcollelem] の 使用は一貫している必要があります。 たとえば、 Get プロパティで 属性を使用する場合は、 Let プロパティにも存在する必要があります。

Typeflags Representation

FUNCFLAG_FDEFAULTCOLLELEMまたはVARFLAG_FDEFAULTCOLLELEMの存在。

//A form has a button on it named Button1. 
//To enable use of the property syntax and efficient use of the !
//syntax, the form describes itself in type info this way.
[
    dual,
    uuid(12345678-1234-1234-1234-123456789ABC),
    helpstring("This is IForm"),
    restricted
]
interface IForm1: IForm
{
    [propget, defaultcollelem] HRESULT Button1(
        [out, retval] Button *Value);
}

//User code may access the button using property syntax or ! syntax.

Sub Test()
Dim f as Form1
Dim b1 As Button
Dim b2 As Button

Set f = Form1

Set b1 = f.Button1        ' Property syntax
Set b = f!Button1        ' ! syntax
End Sub

関連項目

ODL ファイルの構文

ODL ファイルの例

MIDL を使用したタイプ ライブラリの生成