AdoCollection:ForEach()

<< Click to Display Table of Contents >>

Navigation:  Support Classes > AdoCollection Class >

AdoCollection:ForEach()

Previous pageReturn to chapter overviewNext page

Purpose

Evaluate a CodeBlock for every object in the collection

 

Prototype

METHOD ForEach ( uBlock AS USUAL )  AS DWORD PASCAL CLASS AdoCollection

 

Argument(s)

bBlock        Code block or object with eval method that is called for every object

 

Return

nCount        The 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.

Notes

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.

 

Example(s)

FUNCTION ShowFieldNames(oRs AS AdoRecordSet) AS VOID PASCAL&#32;

LOCAL bBlock AS CODEBLOCK 

LOCAL oFlds  AS AdoFields 

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

oFlds := oRs:Fields                         // get fields collection 

oFlds:Foreach(bBlock)                       // display the names of all tables 

RETURN 

 

See Also

AdoCollection, AdoCollection:Count, AdoCollection:Item, AdoCollection:AsArray