combobox中的内存释放问题
我在一个很简单的程序中使用了AddObject
但内存释放出错,请各位帮我看看,谢谢!
procedure TForm1.Button1Click(Sender: TObject);
var i:integer ;
P:PString;
begin
for i:=0 to 1000 do
begin
New(P);
P^:=IntToStr(i);
ComboBox1.Items.AddObject(IntToStr(i),TObject(p));
end ;
ShowMessage('ok');
end;
procedure TForm1.Button2Click(Sender: TObject);
var i:Integer ;
begin
for i:=ComboBox1.Items.Count -1 downto 0 do
begin
if combobox1.Items.Objects[i]<>nil then
ComboBox1.Items.Objects[i].Free ; //这句出错,便获取的Ojbect值是没有错误的.
end ;
ShowMessage('ok');
end;
谢谢!