[Lazarus] global items in TApplication

Graeme Geldenhuys graeme at geldenhuys.co.uk
Sun Sep 15 11:36:18 CEST 2013


On 2013-09-15 04:22, Marc Santhoff wrote:
> How do you handle this?
> How can I meet the spec and put all global into the .dpr-file?


I use the Singleton design pattern for the solution. I often create a
Application Class (nothing to do with TApplication) that keeps track of
such things like global user preference, lookup lists etc.

If other units require references I refactor my class structure so I
have some base class I can pass in to other units. Those units then
reference the passed in instance, and never the original application
class (and related unit) directly. This is called Dependency Injection -
yet another software design pattern that removes hard-coded dependencies.


Design Patterns are your friend! ;-)


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/





More information about the Lazarus mailing list