Posts

Showing posts from April, 2010

Singletons

For a long time now I've been looking for a nice singleton implementation that meets my needs. I want a singleton that: Can't be created more than once. Can't be freed until the program terminates. Can be used as a common base class for all the program's singletons. There are plenty of implementations around that meet requirements 1 and 2, but most of those can't be overridden (usually because they retain a reference to the singleton object in a private global variable or a class var field). Then I found some code by Yoav Abrahami in his article on Delphi3000.com that can be used as a base class. The code was written for a old version of Delphi and used a TStringList to record instances of each singleton class created and only permits one instance of each class. I've adapted Yoav's code to use features of Delphi 2010 to avoid the need for TStringList and use of private global variables. I've also taken advantage of Delphi 2010's new c