1,183
社区成员
发帖
与我相关
我的任务
分享
interface
uses SysUtils;
type
TSingleton = class
public
constructor Create; virtual;
destructor Destroy; override;
end;
var
g_Singleton1: TSingleton; // 全局变量
implementation
constructor TSingleton.Create;
begin
if g_Singleton1 <> nil then
abort
else
g_Singleton1 := Self;
end;
destructor TSingleton.Destroy;
begin
if g_Singleton1 = self then
g_Singleton1 := nil;
inherited Destroy;
end;