如果列表为空
for i:=0 to list.count -1
这样就不循环了
如果不减一,又怕越界,怎么办?
repeat
ShowMessage('aa');
until list.count = 0 ;
if List.Count > 0 then
for i:=0 to list.count -1
begin
{......}
end;
procedure TForm1.Button1Click(Sender: TObject);
var
List: TStringList;
s: string;
begin
List := TStringList.Create;
for s in List do
ShowMessage(s);
List.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
List: TList;
p: Pointer;
begin
List := TList.Create;
for p in List do
ShowMessage(IntToStr(Integer(P)));
List.Free;
end;