L
longsheng
Unregistered / Unconfirmed
GUEST, unregistred user!
我在MyStringList: TStringList中用AddObject('',MyObject)加入了自定义的对象MyObject: TMyObject;在释放TStringList时,需要先释放对象MyObject,于是我在MyStringList的Destroy事件中填加了如下代码:
var
nMyObject: TMyObject;
begin
for i:= 0 to MyStringList.Count - 1 do
begin
nMyObject:=TMyObject(MyStringList.Objects[0])
nMyObject.free;
MyStringList.delete(0);
end;
inherited;
end;
请问:
是先运行nMyObject.free; 再运行MyStringList.delete(0); 好?还是先运行MyStringList.delete(0); 再运行nMyObject.free; 好?
先Free再Delete或先Delete再Free,他们有什么隐患?请各位高手指教!
谢谢!!!
var
nMyObject: TMyObject;
begin
for i:= 0 to MyStringList.Count - 1 do
begin
nMyObject:=TMyObject(MyStringList.Objects[0])
nMyObject.free;
MyStringList.delete(0);
end;
inherited;
end;
请问:
是先运行nMyObject.free; 再运行MyStringList.delete(0); 好?还是先运行MyStringList.delete(0); 再运行nMyObject.free; 好?
先Free再Delete或先Delete再Free,他们有什么隐患?请各位高手指教!
谢谢!!!