用整数使用TStringList的AddObject? [英] Using TStringList's AddObject with integers?
本文介绍了用整数使用TStringList的AddObject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用delphi 7:
Using delphi 7:
- 如何在stringlist项目的对象部分中添加一个整数,
使用AddObject
? - 如何从stringList项目的
属性中检索整数? - 完成后如何释放所有对象并列出
?
推荐答案
Q: 如何使用AddObject向stringlist项目的对象部分添加一个整数?
A:只需将整数值转换为 TObject
A: Just cast the integer value to TObject
List.AddObject('A string',TObject(1));
问: 如何检索整数从stringlist item的对象属性返回?
A:转换为整数对象值
AValue := Integer(List.Objects[i]);
问: 我如何释放所有对象并完成列表?
A:您不需要释放对象列表,因为你没有分配内存。所以只需调用 TStringList
的免费
程序。
A: You don't need free the object list, because you are not assigning memory. so only call the Free
procedure of the TStringList
.
尝试此示例应用程序
{$APPTYPE CONSOLE}
uses
Classes,
SysUtils;
Var
List : TStringList;
i : Integer;
begin
try
List:=TStringList.Create;
try
//assign the string and some integer values
List.AddObject('A string',TObject(1));
List.AddObject('Another string',TObject(100));
List.AddObject('And another string',TObject(300));
//Get the integer values back
for i:=0 to List.Count - 1 do
Writeln(Integer(List.Objects[i]));
finally
//Free the list
List.free;
end;
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
Readln;
end.
这篇关于用整数使用TStringList的AddObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文