Navigation:  Introduction >

Objects and Collections

Previous pageReturn to chapter overviewNext page

There are 17 different DAO object types. VO2Jet has classes for any of these object types.

Each DAO object type other than DaoDbEngine also has a corresponding collection. A collection includes all the existing objects of that type. For example, the Recordsets collection contains all open DaoRecordset objects. Each collection is "owned" by another object at the next higher level in the hierarchy. A DaoDatabase object "owns" a Recordsets collection. Except for the DaoConnection and DaoError objects, every DAO object has a Properties collection.


Each collection is a dynamic list of objects of the same type. The Errors collection consists of one or more Error objects, and the Workspaces collection consists of one or more Workspace objects. The Count property of the collection returns the number of records in a collection.

You can reference objects in a collection by using the item property and specifying a name or a number. When you reference an object (in Visual basic or Visual C++) by number, you should know that the first element in a Collection is allways element 0, and the last element is Collection:count-1.

This is not the way we are used to work with arrays in Visual Objects, and therefore very confusing. VO2Jet translates this automatically for you, so you reference the first element as element 1


very often you see a Visual Basic sample that looks like this.





Visual Basic also knows something that is called a default property, and Item is the default property of Collections, so this code is often written as:




Vo doesn't support the default property so we can't omit the Item in VO


Further, the Properties collection itself is the default collection for the Connection, Command, and Recordset objects, so you can omit those in Visual Basic as well:




All of these syntax forms are identical. In CA-Visual Objects in general we don't know these default properties, so we would have to write it like this




Since Vo2Jet automatically translates the Zero-bases items to 1 based, the final VO2Jet syntax for the first line is:



Processing every object in a collection

When you need to process every object in a collection you could write a loop and ask for every item like this:


 nItems := oCollection:Count

 For i := 1 to nItems

         oItem := oCollection:[Item,i]

         // do what you have to do




This works, but is not very efficient. Every time you query for an item, it has to be looked up in the collection.

We have created 2 alternatives in VO2Jet.

If you want all the objects of a collection, we have created the AsArray() method that transforms the DAO Collection into a VO array, so you can access the elements at full VO speed:


 aItems        := oCollection:AsArray()

 For i := 1 to aLen(aItems)

         oItem := aItems[i]

         // do what you have to do



 // or

 Aeval(aItems, {|oItem| Qout(oItem:Name)})


If you don't want to store all the item objects in an array for later use, we have created even a better way, which is very similar to the For Each construct that is available in Visual Basic, called the ForEach() method. This method accepts a codeblock as a parameter, and that codeblock gets called for every object in the collection. The codeblock received the object as a parameter. If the codeblock returns a logical False the loop through the collection is aborted. The return value of the method is the number of times the codeblock has been caled.




Finally if you have to access the elements by number, we have implemented a caching mechanism so the second time you access the same object in the collection, you get it really fast.