Constructors: CreateEnumerator

CreateEnumerator

Creates a For..Each compatible wrapper around an IEnumerator object.



 Public Function CreateEnumerator(
	  ByVal Obj As IEnumerator ) As IUnknown

Parameters

Obj
[ByVal] IEnumerator. The IEnumerator object that is to be called during For..Each.

Return Values

IUnknown -  A For..Each compatible enumerator.

Remarks

VBCorLib allows for the building of custom enumerators to be used in a For..Each loop context.

To create a custom enumerator please refer to the IEnumerator interface.

In order for VB to utilize your custom IEnumerator object, it must be wrapped in an object that implements the IEnumVariant interface. This is the only interface that VB can use in a For..Each context. By passing in the custom enumerator into the CreateEnumerator function, a wrapper is applied and returned that is then returned in the typical NewEnum function of a class.

Example

 Public Function NewEnum() As IUnknown
     Dim en As New MyEnumerator
     en.Init Me
     Set NewEnum = CreateEnumerator(en)
 End Sub
 
This example creates a custom enumerator object and initializes it with the object that is to be enumerated using the custom enumerator. The custom enumerator is then passed into the CreateEnumerator function and the returned value is then passed back to the calling function.

See Also

Project VBCorLib Overview Class Constructors Overview Constructors Properties Constructors Methods BInt NewApplicationException IEnumerator