<div>Dear Kyley,</div>
<div> </div>
<div><font color="#3366ff">" 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"</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> </div>
<div><font color="#3366ff">"As per the help file, which it seems many have not read.. "<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> </div>
<div>Paul</div>
<div> </div>
<div><span class="gmail_quote">On 20/05/06, <b class="gmail_sendername">Todd Martin</b> <<a href="mailto:toddm@kol.co.nz">toddm@kol.co.nz</a>> 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 : TSingletonObject;<br><br>function GetSingletonInstance : TSingletonObject;<br>begin<br>if (SingletonInstance= nil) then<br>begin<br> CriticalSection.Enter;<br> try<br> if (SingletonInstance= nil) then
<br> begin<br> SingletonInstance:= TSingletonObject.Create;<br> end;<br> finally<br> CriticalSection.Leave;<br> end;<br>end;<br><br>Result := SingletonInstance;<br>end;<br><br><br>----- Original Message -----
<br>From: "Kyley Harris" <<a href="mailto:kyley@harrissoftware.com">kyley@harrissoftware.com</a>><br>To: "NZ Borland Developers Group - Delphi List" <<a href="mailto:delphi@ns3.123.co.nz">delphi@ns3.123.co.nz
</a>><br>Sent: Friday, May 19, 2006 4:52 PM<br>Subject: RE: [DUG] Usage - initialization and finalization<br><br><br>> Thanks. Hadn't thought of that before. It is of course quite possible<br>> for it to be constructed 2 times. Going back to that code sample I
<br>> posted for observation I use this method for creating a Critical<br>> Section. This would probably be a good place to use that seeing as I use<br>> that in a very threaded environment.<br>><br>> -----Original Message-----
<br>> 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>> On Behalf Of Jeremy North<br>> Sent: Friday, 19 May 2006 2:29
p.m.<br>> To: NZ Borland Developers Group - Delphi List<br>> Subject: Re: [DUG] Usage - initialization and finalization<br>><br>> An alternate and thread safe way to perform this operation is to use<br>> InterlockedCompareExchange.
<br>><br>> It is possible (although not very probable) to have FList created<br>> twice without using InterlockedCompareExchange. Probably not worth the<br>> extra effort though.<br>><br>> ms-help://borland.bds4/dllproc/base/interlockedcompareexchange.htm
<br>><br>> This technique is implemented in the TPrivateHeap class in the<br>> PrivateHeap unit. It was originally written by Hallvard Vassbotn. If<br>> you are interested in the inner workings of Delphi and the Compiler,
<br>> you should read his blog (<a href="http://hallvards.blogspot.com/">http://hallvards.blogspot.com/</a>).<br>><br>> For the OP I would minimize the use of the Initialization section to<br>> cases where you really need it. Otherwise your unit cannot be smart
<br>> linked out.<br>><br>> /// code below<br>><br>> unit Unit4;<br>><br>> interface<br>><br>> uses<br>> Windows<br>> , Classes<br>> , SysUtils<br>> ;<br>><br>> function GetList: TList;
<br>><br>> implementation<br>><br>> var<br>> FList: TList;<br>><br>> function GetList: TList;<br>> var<br>> lList: TList;<br>> begin<br>> if FList = nil then<br>> begin<br>> lList :=
TList.Create;<br>> if InterlockedCompareExchange(Integer(FList), Integer(lList), 0) <><br>> 0 then<br>> lList.Free;<br>> end;<br>> result := FList;<br>> end;<br>><br>> initialization
<br>><br>> finalization<br>> FreeAndNil(FList);<br>><br>> end.<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>><br>><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>><br>><br>><br>> --<br>
> No virus found in this incoming 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><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>