ComBoBox中addObject函数的内存释放有关问题?
ComBoBox中addObject函数的内存释放问题???
procedure TForm1.Button1Click(Sender: TObject);
var tmp1:string;
tmp2:^string ;
begin
new(tmp2);
tmp1 := '1 ';
tmp2 ^:= 'abc ';
CbBox1.Items.AddObject(tmp1,TObject(tmp2^));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to CbBox1.Items.Count-1 do
if CbBox1.Items.Objects[i] <> nil then
begin
Dispose(pstring(CbBox1.Items.Objects[i]));
end;
end;
上述语句中,一执行到Dispose就出错,怎么回事???
------解决方案--------------------
CbBox1.Items.AddObject(tmp1,TObject(tmp2^)); ->
CbBox1.Items.AddObject(tmp1,TObject(tmp2));
------解决方案--------------------
这里的问题
CbBox1.Items.AddObject(tmp1,TObject(tmp2));
procedure TForm1.Button1Click(Sender: TObject);
var tmp1:string;
tmp2:^string ;
begin
new(tmp2);
tmp1 := '1 ';
tmp2 ^:= 'abc ';
CbBox1.Items.AddObject(tmp1,TObject(tmp2^));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to CbBox1.Items.Count-1 do
if CbBox1.Items.Objects[i] <> nil then
begin
Dispose(pstring(CbBox1.Items.Objects[i]));
end;
end;
上述语句中,一执行到Dispose就出错,怎么回事???
------解决方案--------------------
CbBox1.Items.AddObject(tmp1,TObject(tmp2^)); ->
CbBox1.Items.AddObject(tmp1,TObject(tmp2));
------解决方案--------------------
这里的问题
CbBox1.Items.AddObject(tmp1,TObject(tmp2));