ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Singleton模式之Delphi实现 (转)

Singleton模式之Delphi实现 (转)

原创 Linux操作系统 作者:worldblog 时间:2007-12-12 11:09:54 0 删除 编辑
Singleton模式之Delphi实现 (转)[@more@]

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;


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-991815/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    6241
  • 访问量
    2411029