<div>Thanks for all of that everybody.</div>
<div> </div>
<div>Kyely, the information on scope, and also the non-existance yet of the Application object during <strong>Initialization</strong> is very helpful thanks.</div>
<div> </div>
<div>"<span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">You don't always have to use initialization to create and finalize to destroy. That would be very resource hungry."</span></div>
<div> </div>
<div>I was thinking of it as an alternative, like <strong>Initialization </strong>as the point to create gloabl UNIT wide VAR .TstringLists etc .. instead of during .onFormCreate, and for freeing stringlists etc .. during
<strong>Finalization</strong> instead of during .<strong>onDestroy</strong></div>
<div> </div>
<div>Reason being . . </div>
<div> </div>
<div>I was wondering whether there are any circumstances where using Finilization to .<strong>free</strong> objects is more reliable than .<strong>ondestroy </strong>? </div>
<div>Is Finalization called after Tform.<strong>onDestroy</strong>, or does it failsafe even if onDestroy fails for some system reason?<br><br>Paul</div>
<div> </div>
<div><span class="gmail_quote">On 19/05/06, <b class="gmail_sendername">Jeremy North</b> <<a href="mailto:jeremy.north@gmail.com">jeremy.north@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">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) <> 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></blockquote></div><br>