Enumerating Collections

A collection is simply a set or group of items, where each can be accessed through its own Interface.  For example, Microsoft Word™ can have multiple documents open at the same time, and it can provide an Interface reference for each open document.

Therefore, enumerating a collection is simply a matter of determining the number of items in the collection, looping through and retrieving the appropriate information for one or more Interface members of the collection.

We'll start off with the Visual Basic syntax and show how to perform the same kind of task with PowerBASIC.

Visual Basic syntax for enumerating a collection looks something like this:

Dim Item  As InterfaceItem

Dim Items As InterfaceItemsCollection

[statements]

For Each Item In Items

  'do something with the Item.member Method/Property, e.g.,

  var$ = Item.StringProp

Next

In PowerBASIC, we can perform the same enumeration.  For example:

DIM oItem  AS InterfaceItem

DIM oItems AS InterfaceItems

[statements]

OBJECT GET oItems.Count TO c&

FOR Index& = 1 TO c&

  OBJECT GET oItems.Item(Index&) TO oItem

  'do something with the Item.member Method/Property, e.g.,

  OBJECT GET oItem.StringProp TO var$$

NEXT

 

See Also

COLLECTION Object Group

What is an object, anyway?

Just what is COM?

What are Type Libraries?