<< Click to Display Table of Contents >> AdoCollection:ForEach() |
![]() ![]() ![]() |
Evaluate a CodeBlock for every object in the collection
METHOD ForEach ( uBlock AS USUAL ) AS DWORD PASCAL CLASS AdoCollection
bBlock Code block or object with eval method that is called for every object
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
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.
FUNCTION ShowFieldNames(oRs AS AdoRecordSet) AS VOID PASCAL 
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
AdoCollection, AdoCollection:Count, AdoCollection:Item, AdoCollection:AsArray