-
-
Save menjaraz/b566898912ef37ddc1e311935939ced5 to your computer and use it in GitHub Desktop.
Esqueleto para criação de uma classe Singleton em Delphi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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