Collections

The dbDAO classes emulate Visual Basic collections by providing member variables that point to collections. As with default values, there is no automatic lookup syntax, which means you have to use an explicit Item method. This method is overloaded to allow you to specify either an ordinal or string index in the collection.

Automatic construction and destruction of these references means that statements of the following kind are valid:

d.m_Tabledefs.Item(i).Name

They result in the correct allocation of the referenced Item method (a TableDef object in this case), and its deallocation when the reference is complete. Of course, for repeated access, it is better to declare an explicit reference, but for one-time use, this is a convenient way to retrieve collection values.

A convenient shorthand for specifying an item in a collection is to use the [ ] operator. The same statement would then be:

d.m_Tabledefs[i].Name

Note If you reference fields by ordinal position cast the index as LONG to prevent the compiler from interpreting “0” as NULL.