Skip to content

Instantly share code, notes, and snippets.

@drgarcia1986
Created February 25, 2014 18:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save drgarcia1986/9214646 to your computer and use it in GitHub Desktop.
Save drgarcia1986/9214646 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