Z
zlj555
Unregistered / Unconfirmed
GUEST, unregistred user!
pMyClass = ^TMyclass;
TMyClass = class
public
name : string;
caption : string;
end;
//TMyList : TList;
//向TMyList中加入值。
procedure TForm1.Button2Click(Sender: TObject);
var
l_pMyClass : pMyClass;
begin
new(l_pMyClass);
if MyList=NIL then MyList := TList.Create;
l_pMyClass^ := TMyClass.Create;
l_pMyClass^.name := 'zlj';
l_pMyclass^.caption :='Caption'+IntToStr(MyList.count);
MyList.Add(l_pMyClass);
end;
//释放的过程。有什么不对请指正???????????谢谢
//这句是不是把占用的内存地址清空??不对的话,该怎么写
1 for i := 0 to MyList.Count -1 do TMyClass(MyList.items^).Free;
和
2 for i := 0 to MyList.Count -1 do dispose(pMyClass(MyList.items));
1 和 2 有什么区别???
这里数量和执行上一语句前的数量一样
ShowMessage(IntToStr(MyList.count));
MyList.Clear; //请问 MyList := NIL;是不是不用clear;
ShowMessage(IntToStr(MyList.count));数量为0
MyList := NIL;
TMyClass = class
public
name : string;
caption : string;
end;
//TMyList : TList;
//向TMyList中加入值。
procedure TForm1.Button2Click(Sender: TObject);
var
l_pMyClass : pMyClass;
begin
new(l_pMyClass);
if MyList=NIL then MyList := TList.Create;
l_pMyClass^ := TMyClass.Create;
l_pMyClass^.name := 'zlj';
l_pMyclass^.caption :='Caption'+IntToStr(MyList.count);
MyList.Add(l_pMyClass);
end;
//释放的过程。有什么不对请指正???????????谢谢
//这句是不是把占用的内存地址清空??不对的话,该怎么写
1 for i := 0 to MyList.Count -1 do TMyClass(MyList.items^).Free;
和
2 for i := 0 to MyList.Count -1 do dispose(pMyClass(MyList.items));
1 和 2 有什么区别???
这里数量和执行上一语句前的数量一样
ShowMessage(IntToStr(MyList.count));
MyList.Clear; //请问 MyList := NIL;是不是不用clear;
ShowMessage(IntToStr(MyList.count));数量为0
MyList := NIL;