⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 singletonunit2.pas

📁 设计模式的源代码 Singleton模式
💻 PAS
字号:
unit SingletonUnit2;


interface

uses classes,SysUtils;

type
  TSingletonList = class(TList);

  TSingletonl = class
  public
    constructor Create;virtual;
    destructor Destroy; override;
  protected
    function lookup(PSingleton: TSingletonl): boolean;
  end;

  TChildSingletonl = class(TSingletonl);

var
  Glob_Singletonlist: TSingletonList; //ㄏノ俱砰跑计

implementation

constructor TSingletonl.Create;
begin
  if lookup(self) then
    Abort
  else
    Glob_Singletonlist.Add(self);
end;

destructor TSingletonl.Destroy;
begin
  if lookup(self) then
  begin
    Glob_Singletonlist.Remove(self);
    inherited Destroy;
  end;
end;

function TSingletonl.lookup(PSingleton: TSingletonl): boolean;
var
  i: word;
  plSingleton: TSingletonl;
begin
  result := false;
  if (Glob_Singletonlist = nil) or (Glob_Singletonlist.Count = 0) then
  begin
    Glob_Singletonlist := TSingletonList.Create;
    result := false;
    Exit;
  end;
  for i := 0 to Glob_Singletonlist.Count - 1 do
  begin
    plSingleton := Glob_Singletonlist.Get(i);
    if (plSingleton.ClassName = PSingleton.ClassName) then
      result := true;
  end;
end;


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -