delphi 内存释放的问题?
怎么释放FOR里面的内容?procedureTForm1.Button1Click(Sender:TObject);constLetters='a,b,c,d,e';va...
怎么释放FOR里面的内容?
procedure TForm1.Button1Click(Sender: TObject);
const
Letters='a,b,c,d,e';
var
str:TstringList;
i:integer;
begin
str:=TStringList.Create;
str.CommaText:=Letters;
for i := 0 to str.Count - 1 do begin
ShowMessage(str[i]);
end;
str.Free;
end;
end. 展开
procedure TForm1.Button1Click(Sender: TObject);
const
Letters='a,b,c,d,e';
var
str:TstringList;
i:integer;
begin
str:=TStringList.Create;
str.CommaText:=Letters;
for i := 0 to str.Count - 1 do begin
ShowMessage(str[i]);
end;
str.Free;
end;
end. 展开
2个回答
展开全部
不用释放,只要你的str最终释放了就可以了
最好加上try finally end
procedure TForm1.Button1Click(Sender: TObject);
const
Letters='a,b,c,d,e';
var
str:TstringList;
i:integer;
begin
str:=TStringList.Create;
try
str.CommaText:=Letters;
for i := 0 to str.Count - 1 do begin
ShowMessage(str[i]);
end;
finally
str.Free;
end;
end;
end.
最好加上try finally end
procedure TForm1.Button1Click(Sender: TObject);
const
Letters='a,b,c,d,e';
var
str:TstringList;
i:integer;
begin
str:=TStringList.Create;
try
str.CommaText:=Letters;
for i := 0 to str.Count - 1 do begin
ShowMessage(str[i]);
end;
finally
str.Free;
end;
end;
end.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询