用addobject 添加拉一个类,可是在delete 和clear listbox时不会自动释放,我写拉下面的代码,也没有释放内存,请问各位大侠,错在那里,怎么改
procedure TForm1.Button1Click(Sender: TObject);
var
ButtonTest : TButton;
i : integer;
begin
for i := 1 to 1000 do
begin
ButtonTest:= TButton.Create(self);
ListBox1.Items.AddObject(inttostr(i)+'东方宫地方国风的东方宫',TObject(ButtonTest));
end;
end;procedure TForm1.Button4Click(Sender: TObject);
var
i : integer;
begin
for i:=0 to ListBox1.Count - 1 do
begin
TButton(ListBox1.Items.Objects[0]).free;
ListBox1.Items.Objects[0]:=nil;
end;
ListBox1.Items.Clear;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ButtonTest : TButton;
i : integer;
begin
for i := 1 to 1000 do
begin
ButtonTest:= TButton.Create(self);
ListBox1.Items.AddObject(inttostr(i)+'东方宫地方国风的东方宫',TObject(ButtonTest));
end;
end;procedure TForm1.Button4Click(Sender: TObject);
var
i : integer;
begin
for i:=0 to ListBox1.Count - 1 do
begin
TButton(ListBox1.Items.Objects[0]).free;
ListBox1.Items.Objects[0]:=nil;
end;
ListBox1.Items.Clear;
end;
解决方案 »
- 继续请教关于PEditor 这个问题。
- 年终放分了,散进所有分.
- 求delphi7的报表教程
- 高难度:如何禁止删除指定的文件或文件夹.
- 小弟需要做一个 发送/接受邮件的程序,单没有思路!
- 请问如何获得打印机状态?比如是否联机
- 请教:关于数据库自动备份和数据库显示的问题,请大家帮忙。(急)
- 请问‘多层’有没有平台限制,必须在WINDOWS系统中才能实现多层么??
- stringGrid 颜色控制问题!
- delphi中如何设置1udp soket为非阻塞soket
- 安装组件出错Could not create output file 'c:\program files\borland\delphi7\Projects\Bpl\Userdoc.bpl'在线等急,马上给分
- 系统做好了.要写个程序把分离出来xxx.MDF和xxx.LDF导入到数据库中,怎么办?
...
var
i : integer;
begin
for i:=0 to ListBox1.Count - 1 do
begin
TButton(ListBox1.Items.Objects[i]).free;// 是"i"
ListBox1.Items.Objects[i]:=nil;
end;
ListBox1.Items.Clear;
end;
var
i : integer;
begin
for i:=0 to ListBox1.Count - 1 do
begin
TButton(ListBox1.Items.Objects[i]).free;
ListBox1.Items.Objects[i]:=nil;
end;
ListBox1.Items.Clear;
end;循环里面要用i呀
var
i : integer;
begin
for i:=0 to ListBox1.Count - 1 do
begin
TButton(ListBox1.Items.Objects[i]).free;
ListBox1.Items.Objects[i]:=nil;
end;
ListBox1.Items.Clear;
end;
var
i : integer;
begin
for i:=0 to ListBox1.Items.Count - 1 do
begin
FreeAndNil(ListBox1.Items.Objects[ListBox1.Count - 1]);
end;
ListBox1.Items.Clear;
end;
For I:=ListBox1.Items.count-1 downto 0 do
begin
//同上
end