Previous Table of Contents Next


19.10.1 Mapping for OMG IDL Arrays and Sequences to Collections


   Some Automation controllers do not support the use of SAFEARRAYs. For this reason, arrays and sequences can also be mapped to OLE collection objects.

   A collection object allows generic iteration over its elements. While there is no explicit ICollection type interface, OLE does specify guidelines on the properties and methods a collection interface should export.

   // ODL[odl, dual, uuid(...)]interface DICollection: IDispatch {

   [propget] HRESULT Count([retval,out] long * count);[propget, id(DISPID_VALUE)] HRESULT Item([in] long index, [retval,out] VARIANT * val);

   [propput, id(DISPID_VALUE)] HRESULT Item([in] long index,[in] VARIANT val);[propget, id(NEW_ENUM)] HRESULT _NewEnum([retval, out] IEnumVARIANT * newEnum);

   }

   The UUID for DICollection is:

   {A8B553C9-3B72-11cf-BBFC-444553540000}

   This interface can also be implemented as generic (nondual) Automation Interface, in which case it is named DCollection and its UUID is:

   {E977F909-3B75-11cf-BBFC-444553540000}

   In controller scripting languages such as VBA in MS-Excel, the FOR...EACH language construct can automatically iterate over a collection object such as that previously described.

   ‘ Visual Basic:Dim doc as ObjectFor Each doc in DocumentCollectiondoc.Visible = FalseNext doc

   The specification of DISPID_VALUE as the id() for the Item property means that access code like the following is possible.

   ‘ Visual Basic:Dim docs as ObjectSet docs = SomeCollection

   docs(4).Visible = False

   Multidimensional arrays can be mapped to collections of collections with access code similar to the following.

   ‘ Visual BasicSet docs = SomeCollection

   docs.Item(4).Item(5).Visible = False

   If the Collection mapping for OMG IDL Arrays and Sequences is chosen, then the signatures for operations accepting SAFEARRAYs should be modified to accept a VARIANT instead. In addition, the implementation code for the View wrapper method should detect the kind of object being passed.