"For In" 的问题 ( 积分: 50 )

  • 主题发起人 Delphi老将
  • 开始时间
D

Delphi老将

Unregistered / Unconfirmed
GUEST, unregistred user!
有谁能举个例子,如何把D2005新增的"For In"循环用在TObjectList上?
 
有谁能举个例子,如何把D2005新增的"For In"循环用在TObjectList上?
 
补充:
在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;
 
大概这样吧,没有装过delphi 2005
var
S : String;
TS : TStringList;
begin
...
for S in TS do
begin
...
end;
...
end;
 
学pascal五年了,用delphi快两年了,开眼界了
从来都是
for i:= A to B
第一次见
for ... in 循环,真是长见识呀!超级爽
谢谢楼主!
 
楼主有什么好的资料,能否发一点给我,英文的也没问题,我这虽然也收藏不不少,但不少都是泛泛而谈的,从网上各大论坛收集的,都比较老了,没多少意思,请楼主赐教!
 
顶部