, .
SmartPtr, Barry Kelly, D2010 . smartptr D2009.
.
, smartptr :) - D2010: (
, D2010.
type
TSmartPtr<T: class> = class(TInterfacedObject, TFunc<T>)
private
FValue: T;
public
constructor Create(AValue: T);
destructor Destroy; override;
function Invoke: T;
end;
TSmartPtrArray<T: class> = array of TFunc<T>;
implementation
{ TObjectHandle }
constructor TSmartPtr<T>.Create(AValue: T);
begin
FValue := AValue;
end;
destructor TSmartPtr<T>.Destroy;
begin
if Assigned(FValue) then
FValue.Free;
end;
function TSmartPtr<T>.Invoke: T;
begin
Result := FValue;
end;