Title: VB (for..each) to delphi
The  "For Each" in VB is used alot for things like Collections and or recordsets.
 
I.e. For Each Item in MyCollection
         fName=Mycollection.name
      next
 
or   For Each Item in MyRecordset
        fName=MyRecordset.fields("name").value
     next
 
Snipped from MSDN CD :-
 

Repeats a group of statements for each element in an array or collection.

Syntax

For Each element In group
[statements]
[Exit For]
[statements]

Next [element]

The For...Each...Next statement syntax has these parts:

Part Description
element Required. Variable used to iterate through the elements of the collection or array. For collections, element can only be a Variant variable, a generic object variable, or any specific object variable. For arrays, element can only be a Variant variable.
group Required. Name of an object collection or array (except an array of user-defined types).
statements Optional. One or more statements that are executed on each item in group.

Remarks

The For...Each block is entered if there is at least one element in group. Once the loop has been entered, all the statements in the loop are executed for the first element in group. If there are more elements in group, the statements in the loop continue to execute for each element. When there are no more elements in group, the loop is exited and execution continues with the statement following the Next statement.

Any number of Exit For statements may be placed anywhere in the loop as an alternative way to exit. Exit For is often used after evaluating some condition, for example If…Then, and transfers control to the statement immediately following Next.

You can nest For...Each...Next loops by placing one For...Each...Next loop within another. However, each loop element must be unique.

Note   If you omit element in a Next statement, execution continues as if element is included. If a Next statement is encountered before its corresponding For statement, an error occurs.

You can't use the For...Each...Next statement with an array of user-defined types because a Variant can't contain a user-defined type.

 

Cheers, Jeremy Coulter

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Ben Taylor
Sent: Monday, August 09, 1999 17:51
To: Multiple recipients of list delphi
Subject: [DUG]: VB (for..each) to delphi

Hi!

I have a piece of example code in vb that i want to
use in delphi. but...
does anyone know offhand what constructs vb uses in
order to perform for..each operations, eg:

  For Each strName In SFS.SymbolNames
    txtSymNames.AddItem strName
  Next strName

ie does it use an IStrings interface or similar? as
far as i can tell, SFS.SymbolNames has an IDispatch
interface, but thats as far as i can go... i can use
a variant to (partially) access it, but i was trying
to get a better-typed solution :-)

or on a similar note, is there a way of finding out
what interfaces/guids an IUnknown supports?

Comments/suggestions appreciated!

Thanks,
Ben.

====================
Ben Taylor
Software Developer
[EMAIL PROTECTED]
www.tvd.co.nz

Reply via email to