singletonunit1.pas

来自「设计模式的源代码 Singleton模式」· PAS 代码 · 共 36 行

PAS
36
字号
unit SingletonUnit1;

interface
uses SysUtils;
type
  TSingleton = class
  public
    constructor Create; virtual;
    destructor Destroy; override;
  end;
var
  Glob_Singleton1: TSingleton; //ㄏノ俱砰跑计


implementation

constructor TSingleton.Create;
begin
  if Glob_Singleton1 <> nil then
    abort
  else
    Glob_Singleton1 := Self;
end;

destructor TSingleton.Destroy;
begin
  if Glob_Singleton1 = self then
    Glob_Singleton1 := nil;
  inherited Destroy;
end;



end.

⌨️ 快捷键说明

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