<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="place"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
p
        {mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle22
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=blue>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Yes. The application object does exist, so
in my last post I definitely typo’d saying it does not exist. Sorry.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>In a normal application the Application
Var is created in Controls.pas initialization. <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>But be aware that your entire application
is generally executing from the Application.Run context, so anything outside of
this may not behave as you expect such as receiving windows events and such. Not
that I’ve tested that because I wouldn’t use finalization or
initialization for anything other than basic things<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
delphi-bounces@ns3.123.co.nz [mailto:delphi-bounces@ns3.123.co.nz] <b><span
style='font-weight:bold'>On Behalf Of </span></b>Paul A Norman<br>
<b><span style='font-weight:bold'>Sent:</span></b> Tuesday, 23 May 2006 5:41
p.m.<br>
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName w:st="on">karlreynolds@xtra.co.nz</st1:PersonName>;
<st1:PersonName w:st="on">NZ Borland Developers Group - Delphi List</st1:PersonName><br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [DUG] Usage -
initialization and finalization</span></font><o:p></o:p></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>P.S. the Application object is used whcih some one earler suggested was
not possible.<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>The application does work!<br>
<br>
<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><span class=gmailquote><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>On 23/05/06, <b><span style='font-weight:bold'>Paul A
Norman</span></b> <<a href="mailto:paul.a.norman@gmail.com">paul.a.norman@gmail.com</a>>
wrote:</span></font></span> <o:p></o:p></p>
<div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Just back in the basics where I am for a moment,<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>This is some code I found following a link that Stefan suggested in
another thread today. <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>What is the benefit of doing it all in <strong><b><font
face="Times New Roman">initialization</font></b></strong> and <strong><b><font
face="Times New Roman">finalization</font></b></strong> if it were
contained in a form unit (which it was not incidentily)? <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>initialization<br>
begin<br>
TComObjectFactory.Create(ComServer, TOurNSHandler,
Class_OurNSHandler,<br>
'OurNSHandler', 'OurNSHandler', ciMultiInstance,
tmApartment);<o:p></o:p></span></font></p>
</div>
<div>
<p><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>
Table := TTable.Create(nil);<br>
table.DatabaseName := ExtractFilePath(Application.ExeName);<br>
table.TableName := DatabaseFile;<br>
table.active := true;<br>
end;<o:p></o:p></span></font></p>
<p><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>finalization<br>
table.free;<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><br>
<br>
<o:p></o:p></span></font></p>
</div>
<div><span id="q_10b5fc168fe36e76_1">
<p class=MsoNormal><span class=gmailquote><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>On 23/05/06, <b><span style='font-weight:bold'>Karl @
Work</span></b> <<a href="mailto:karlreynolds@xtra.co.nz" target="_blank">
karlreynolds@xtra.co.nz </a>> wrote:</span></font></span><span class=e> </span></span><o:p></o:p></p>
</div>
<div><span id="q_10b5fc168fe36e76_3">
<p class=MsoNormal><span class=e><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>> I'm curious as to why each of your consuming
units needs to keep a</span></font></span><br>
<span class=e>> reference to the singleton? </span><br>
<span class=e>></span><br>
<span class=e>> IMHO, surely the whole point about a singleton is that you
don't keep </span><br>
<span class=e>> references per se to it.</span><br>
<span class=e>></span><br>
<span class=e>> When you need to access the singleton, you should just call
your</span><br>
<span class=e>> Singleton function declared in your MySingletonUnit unit? </span><br>
<span class=e>></span><br>
<span class=e>> Surely that would result in a whole lot less reference
counting, and </span><br>
<span class=e>> worrying about who's holding on to it and when they drop
their</span><br>
<span class=e>> references, etc.</span><br>
<br>
<span class=e>I would prefer not to keep references to the singleton in the
consuming </span><br>
<span class=e>units, it's just that I haven't found another way to ensure that
it will </span><br>
<span class=e>free itself both (a) after everything else has finished using it
and (b)</span><br>
<span class=e>before the program finishes. The problem is that the singleton
can't be </span><br>
<span class=e>cleaned up in the finalization of its own unit because there are
still </span><br>
<span class=e>references to it which are accessed after that.</span><br>
<br>
<span class=e>Cheers,</span><br>
<span class=e>Carl</span><br>
<br>
<br>
<o:p></o:p></p>
</div>
</span>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><span class=q><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>_______________________________________________</span></font></span><br>
<st1:place w:st="on"><span class=q>Delphi</span></st1:place><span class=q>
mailing list </span><br>
<span class=q><a href="mailto:Delphi@ns3.123.co.nz" target="_blank">Delphi@ns3.123.co.nz
</a></span><br>
<span class=q><a href="http://ns3.123.co.nz/mailman/listinfo/delphi"
target="_blank">http://ns3.123.co.nz/mailman/listinfo/delphi</a></span><br>
<br>
<o:p></o:p></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><br>
<o:p></o:p></span></font></p>
</div>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
</div>
</body>
</html>