Re: [Lazarus] global items in TApplication

2013-09-16 Thread Graeme Geldenhuys
On 2013-09-15 15:57, Martin wrote: > global war, but in implementation > Correct, or just use a "lazyman's singleton" function. 8<-8<-8<-8<-8< interface function GlobalFoo: TFoo; implementation var uFoo: TFoo; function GlobalFoo: TF

Re: [Lazarus] global items in TApplication

2013-09-15 Thread Marc Santhoff
On So, 2013-09-15 at 15:57 +0100, Martin wrote: > On 15/09/2013 15:20, Marc Santhoff wrote: > > It's not in question how to implement global objects. Some are > > singletons by design and others are not in code but work like they were, > > because the only place the constructor is (allowed to be) c

Re: [Lazarus] global items in TApplication

2013-09-15 Thread Marc Santhoff
On So, 2013-09-15 at 15:54 +0100, Martin wrote: > On 15/09/2013 15:24, Marc Santhoff wrote: > > I can, but then I'd have to choose one of two solutions I don't like: > > having to free the automatically created TApplication object or change > > forms.pp. > > Create a descendant of TComponent, an

Re: [Lazarus] global items in TApplication

2013-09-15 Thread Martin
On 15/09/2013 15:20, Marc Santhoff wrote: It's not in question how to implement global objects. Some are singletons by design and others are not in code but work like they were, because the only place the constructor is (allowed to be) called is the inittialization section. The qeustion is where

Re: [Lazarus] global items in TApplication

2013-09-15 Thread Martin
On 15/09/2013 15:24, Marc Santhoff wrote: I can, but then I'd have to choose one of two solutions I don't like: having to free the automatically created TApplication object or change forms.pp. Create a descendant of TComponent, and have it owned by the application, that should take care of it

Re: [Lazarus] global items in TApplication

2013-09-15 Thread Marc Santhoff
On Sa, 2013-09-14 at 21:24 -0700, leledumbo wrote: > In short, you can't put it in the .dpr if you want it to be accessible from > all units. Actually, there's not really any magic behind TApplication, you > can still create your own TApplication descendant (preferably in its own > unit) and assign

Re: [Lazarus] global items in TApplication

2013-09-15 Thread Marc Santhoff
On So, 2013-09-15 at 10:36 +0100, Graeme Geldenhuys wrote: > 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 (no

Re: [Lazarus] global items in TApplication

2013-09-15 Thread Graeme Geldenhuys
On 2013-09-15 10:36, Graeme Geldenhuys wrote: > class (and related unit) directly. This is called Dependency Injection - > yet another software design pattern that removes hard-coded dependencies. I forgot to mention, using Interfaces are also immensely useful in this situation. Also makes it ver

Re: [Lazarus] global items in TApplication

2013-09-15 Thread Graeme Geldenhuys
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 globa

Re: [Lazarus] global items in TApplication

2013-09-14 Thread leledumbo
s hidden in the implementation. A single unit that is set as application configuration is good enough. -- View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-global-items-in-TApplication-tp407p408.html Sent from the Free Pascal - Lazarus mailing list archiv

[Lazarus] global items in TApplication

2013-09-14 Thread Marc Santhoff
Hi, in the process of restructuring an old application I'm stuck on the question where to put globals. For example a global configuration object that has to be available in many units. The problem ist: - I cannot include the main program file (.lpr) in the "uses" clause, which means simple varia