补充:
在Borland的帮助中写到:
Iteration Over Containers Using For statements
Both Delphi for .NET and for Win32 support for-element-in-collection style iteration over containers. The following container iteration patterns are recognized by the compiler:
for Element in ArrayExpr do Stmt
for Element in StringExpr do Stmt
for Element in SetExpr do Stmt
for Element in CollectionExpr do Stmt
......
The following classes and their descendents support the for-in syntax:
TList
TCollection
TStrings
TInterfaceList
TComponent
TMenuItem
TCustomActionList
TFields
TListItems
TTreeNodes
TToolBar
帮助中未给出使用Container的例子,不幸的是这样的代码是不工作的:
var
LObj : TObject;
LObjs : TObjectList;
begin
...
for LObj in LObjs do
begin
...
end;
...
end;