type
TSingleton = class(TObject)
public
A : Integer;
class function NewInstance: TObject; override;
procedure FreeInstance; override;
class function RefCount: Integer;
end;
implementation
var
Instance : TSingleton = nil;
Ref_Count : Integer = 0;
procedure TSingleton.FreeInstance;
begin
Dec( Ref_Count );
if ( Ref_Count = 0 ) then
begin
Instance := nil;
// Destroy private variables here
inherited FreeInstance;
end;
end;
class function TSingleton.NewInstance: TObject;
begin
if ( not Assigned( Instance ) ) then
begin
Instance := inherited NewInstance as TSingleton;
// Initialize private variables here, like this:
TSingleton(Instance).a :3D 1;
end;
Result := Instance;
Inc( Ref_Count );
end;
class function TSingleton.RefCount: Integer;
begin
Result := Ref_Count;
end;
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




