CnPack Forum

#1 不得不说的delphi技巧 之二-----------智能指针
先直接看用法

procedure p();
var
t: TT;
begin
t:=TT.create;
TSafeObject.safeObject(t); //用智能指针保护t对象
//现在，t对象无需手工free,不管过程内发生什么事，它在过程退出后都会自动释放
end;

下面是TSafeObject的定义

TSafeObject=class(TInterfacedObject)
private
obj: TObject;
destructor Destroy(); override;
constructor create(obj: TObject); overload;
public
class function safeObject(instance: TObje ..

#1 >>Next Page

Forum:技术板块灌水区 ...
Thread:不得不说的delphi技巧 ...
Next Thread:TInterfaceObject的子 ...

Home
Login

Powered by Discuz!