好像是 Delphi 2005 开始 Delphi 就开始支持一个新的功能 For … in … 这个在其他语言中早就有但很方便的功能,(其实真的感觉好用是后来到C#中使用才体会到它的方便)。
for … in … 语句用于遍历一个集合,由于不能像类C语言可以就地声明变量,每次用循环就有一点别扭(不仅仅是for in ,包括所有的关于计数类循环),一般用法如下:
//遍历列表 TStringlist
begin
for s in sl do
begin
showmessage(s);
end;
end;
//遍历数组
demoArray:array[0..10] of integer = (1,2,3,4,5,6,7,8,9,10);
begin
for i in demoArray do
begin
showmessage(inttostr(i));
end;
end;