一个不解的问题~~关于tlist
- Delphi(Pascal) code
procedure TForm1.btn1Click(Sender: TObject);var l: tlist; s: TShape;begin l := TList.Create; s := TShape.Create(nil); l.Add(shp1); //shp1 是一个已经存在的组件 s := l.Items[0]; s.Free;
end;
释放的是s,为什么shp1也会没有?
[解决办法]
s := TShape.Create(nil);
s是TShape的实例,并分配了内存地址
l.Items[0]即是shp1
s:= l.Items[0];
s地址已经指向了shp1的地址,2者指向同一地址啦
所以s.free也就把shp1也free掉了