>> Just to add my 2c worth :-). Every moderately sophisticated Delphi
>> application I have worked with has got it's own way of handling form
>> creation and referencing. This is usually through some sort custom built
>> FormController type object. Using Global variables just doesn't cut it.
>
>I agree.
>
>But I am thankful they didn't create a headless monster like the
>"C++ static object creation order" nightmare.
"Me too" on globals.
As for creation order nightmares, I find unit intialization sections can
become similarly problematic on large projects:
A common technique for global objects is to create them in the
initialization section of the unit which implements the global object's
class. This is well and good until someone, perhaps inadvertently,
introduces a circular reference in a uses clause.
eg
UnitA exposes GlobalObjectA and creates GlobalObjectA in its
initialization section
UnitB uses UnitA, referencing GlobalObjectA in its intialization section.
At some stage a unit is added to UnitA's uses clause which in turn uses
UnitB.
At application startup, for UnitA, the units in its uses clauses
(including UnitB)
are completely processed before the initialization section fires.
UnitB attempts to access the uninitialised GlobalObjectA and its AV-a-gogo.
My solution for this is to avoid such globals and use singletons instead -
creating an instance of the class of the previously global object wherever
I need it. As its a singleton, it only gets constructed when there are no
other references around. For objects with a large construction overhead -
database connections, OS resources etc, I relax the constraint and ensure
there is a reference for the lifetime of the application - by using an
initialization-created and unit-scoped (not global) reference to the
singleton.
I have created generic singleton base classes which descend from TObject,
TInterfacedObject and TForm which behave like any other class - no special
constructor-methods. Everyone is welcome to the source, just sing out.
Paul.
----------------------------------------------------------
Paul Spain, Excellent Programming Company
mailto:[EMAIL PROTECTED]
----------------------------------------------------------
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"