<div>Dear&nbsp; Kyley,</div>
<div>&nbsp;</div>
<div><font color="#3366ff">&quot;&nbsp;It contains statements that are executed when the main program terminates<br>(unless the Halt procedure is used to terminate the program). Use the<br>finalization section to free resources that are allocated in the
<br>initialization section&quot;</font><br><br>Thats the sort of stuff I was looking for in the help systrem. Which version of Delphi (help) was that in?</div>
<div>So far I have not found it in D2005.</div>
<div>&nbsp;</div>
<div><font color="#3366ff">&quot;As per the help file, which it seems many have not read.. &quot;<br></font></div>
<div>You say that Finalization does not happen on halt.</div>
<div>Is there anything that can be caused to do cleanup if halt is executed? Or is it utterly final?</div>
<div>&nbsp;</div>
<div>Paul</div>
<div>&nbsp;</div>
<div><span class="gmail_quote">On 20/05/06, <b class="gmail_sendername">Todd Martin</b> &lt;<a href="mailto:toddm@kol.co.nz">toddm@kol.co.nz</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi Kyley<br><br>There is another option. The double check locking pattern. Once instantiated<br>the critical section is no longer used.
<br><br>var<br>SingletonInstance&nbsp;&nbsp;: TSingletonObject;<br><br>function GetSingletonInstance&nbsp;&nbsp;: TSingletonObject;<br>begin<br>if (SingletonInstance= nil) then<br>begin<br>&nbsp;&nbsp; CriticalSection.Enter;<br>&nbsp;&nbsp; try<br>&nbsp;&nbsp;&nbsp;&nbsp; if (SingletonInstance= nil) then
<br>&nbsp;&nbsp;&nbsp;&nbsp; begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SingletonInstance:= TSingletonObject.Create;<br>&nbsp;&nbsp;&nbsp;&nbsp; end;<br>&nbsp;&nbsp; finally<br>&nbsp;&nbsp;&nbsp;&nbsp; CriticalSection.Leave;<br>&nbsp;&nbsp; end;<br>end;<br><br>Result := SingletonInstance;<br>end;<br><br><br>----- Original Message -----
<br>From: &quot;Kyley Harris&quot; &lt;<a href="mailto:kyley@harrissoftware.com">kyley@harrissoftware.com</a>&gt;<br>To: &quot;NZ Borland Developers Group - Delphi List&quot; &lt;<a href="mailto:delphi@ns3.123.co.nz">delphi@ns3.123.co.nz
</a>&gt;<br>Sent: Friday, May 19, 2006 4:52 PM<br>Subject: RE: [DUG] Usage - initialization and finalization<br><br><br>&gt; Thanks. Hadn't thought of that before. It is of course quite possible<br>&gt; for it to be constructed 2 times. Going back to that code sample I
<br>&gt; posted for observation I use this method for creating a Critical<br>&gt; Section. This would probably be a good place to use that seeing as I use<br>&gt; that in a very threaded environment.<br>&gt;<br>&gt; -----Original Message-----
<br>&gt; From: <a href="mailto:delphi-bounces@ns3.123.co.nz">delphi-bounces@ns3.123.co.nz</a> [mailto:<a href="mailto:delphi-bounces@ns3.123.co.nz">delphi-bounces@ns3.123.co.nz</a>]<br>&gt; On Behalf Of Jeremy North<br>&gt; Sent: Friday, 19 May 2006 2:29 
p.m.<br>&gt; To: NZ Borland Developers Group - Delphi List<br>&gt; Subject: Re: [DUG] Usage - initialization and finalization<br>&gt;<br>&gt; An alternate and thread safe way to perform this operation is to use<br>&gt; InterlockedCompareExchange.
<br>&gt;<br>&gt; It is possible (although not very probable) to have FList created<br>&gt; twice without using InterlockedCompareExchange. Probably not worth the<br>&gt; extra effort though.<br>&gt;<br>&gt; ms-help://borland.bds4/dllproc/base/interlockedcompareexchange.htm
<br>&gt;<br>&gt; This technique is implemented in the TPrivateHeap class in the<br>&gt; PrivateHeap unit. It was originally written by Hallvard Vassbotn. If<br>&gt; you are interested in the inner workings of Delphi and the Compiler,
<br>&gt; you should read his blog (<a href="http://hallvards.blogspot.com/">http://hallvards.blogspot.com/</a>).<br>&gt;<br>&gt; For the OP I would minimize the use of the Initialization section to<br>&gt; cases where you really need it. Otherwise your unit cannot be smart
<br>&gt; linked out.<br>&gt;<br>&gt; /// code below<br>&gt;<br>&gt; unit Unit4;<br>&gt;<br>&gt; interface<br>&gt;<br>&gt; uses<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Windows<br>&gt;&nbsp;&nbsp; , Classes<br>&gt;&nbsp;&nbsp; , SysUtils<br>&gt;&nbsp;&nbsp; ;<br>&gt;<br>&gt; function GetList: TList;
<br>&gt;<br>&gt; implementation<br>&gt;<br>&gt; var<br>&gt;&nbsp;&nbsp; FList: TList;<br>&gt;<br>&gt; function GetList: TList;<br>&gt; var<br>&gt;&nbsp;&nbsp; lList: TList;<br>&gt; begin<br>&gt;&nbsp;&nbsp; if FList = nil then<br>&gt;&nbsp;&nbsp; begin<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; lList := 
TList.Create;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; if InterlockedCompareExchange(Integer(FList), Integer(lList), 0) &lt;&gt;<br>&gt; 0 then<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lList.Free;<br>&gt;&nbsp;&nbsp; end;<br>&gt;&nbsp;&nbsp; result := FList;<br>&gt; end;<br>&gt;<br>&gt; initialization
<br>&gt;<br>&gt; finalization<br>&gt;&nbsp;&nbsp; FreeAndNil(FList);<br>&gt;<br>&gt; end.<br>&gt;<br>&gt; _______________________________________________<br>&gt; Delphi mailing list<br>&gt; <a href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz
</a><br>&gt; <a href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a><br>&gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Delphi mailing list
<br>&gt; <a href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</a><br>&gt; <a href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a><br>&gt;<br>&gt;<br>&gt;<br>&gt; --<br>
&gt; No virus found in this incoming message.<br>&gt; Checked by AVG Free Edition.<br>&gt; Version: 7.1.392 / Virus Database: 268.5.6/340 - Release Date: 15/05/2006<br>&gt;<br>&gt;<br><br><br><br>--<br>No virus found in this outgoing message.
<br>Checked by AVG Free Edition.<br>Version: 7.1.392 / Virus Database: 268.5.6/340 - Release Date: 15/05/2006<br><br>_______________________________________________<br>Delphi mailing list<br><a href="mailto:Delphi@ns3.123.co.nz">
Delphi@ns3.123.co.nz</a><br><a href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a><br></blockquote></div><br>