Skip to content

Instantly share code, notes, and snippets.

@menjaraz
Forked from drgarcia1986/Singleton.Example.pas
Created January 5, 2018 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save menjaraz/b566898912ef37ddc1e311935939ced5 to your computer and use it in GitHub Desktop.
Save menjaraz/b566898912ef37ddc1e311935939ced5 to your computer and use it in GitHub Desktop.
Esqueleto para criação de uma classe Singleton em Delphi
unit Singleton.Example;
interface
type
TMyClass = class
strict private
class var FInstance : TMyClass;
private
class procedure ReleaseInstance();
public
class function GetInstance(): TMyClass;
end;
implementation
{ TMyClass }
class function TMyClass.GetInstance: TMyClass;
begin
if not Assigned(Self.FInstance) then
self.FInstance := TMyClass.Create;
Result := Self.FInstance;
end;
class procedure TMyClass.ReleaseInstance;
begin
if Assigned(Self.FInstance) then
Self.FInstance.Free;
end;
initialization
finalization
TMyClass.ReleaseInstance();
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment