Navigation:  DAO Collection Classes > DaoCollection Class >

DaoCollection:ForEach() method

Previous pageReturn to chapter overviewNext page

Purpose

Evaluate a CodeBlock for every object in the collection

 

Parameters

bBlockCode block that is called for every object

 The codeblock gets ONE argument, i.e. the Object

 If the Codeblock returns FALSE the loop through the collection is cancelled

 

Returns

nCountThe number of objects that has been processed

 if you abort the loop by returning FALSE from the Codeblock, than this last object is included as well

 

Description

 

Visual basic has the FOR EACH loop construct that allows you to evaluate code for every element in a collection, without having to set up a loop counter and keeping track of all the elements The ForEach() Method of the Collection emulates this in Visual Objects.

 

NOTE:

 

Using ForEach() is faster than using the Item access of the collection and also has less overhead than calling oColl:AsArray() to convert the collection into an array.

 

Class

DaoCollection        

 

See Also

DaoCollection:AsArray        Returns collection in the form of an VO array

DaoCollection:Item        Access an individual object in the collection

DaoCollection:Count        Number of items in the collection

 

Example

 

function ShowTableNames(oDb as DaoDatabase) AS VOID PASCAL

 

local bBlock as CodeBlock

 

local oTds   as DaoTableDefs

 

bBlock := {|oObject|Qout(oObject:name),TRUE}

 

oTd := oDb:TableDefs                        // get tabledefs collection

 

oTd:Foreach(bBlock}                         // display the names of all tables

 

RETURN