<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;}
span.EmailStyle18
        {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'>Halt is utterly final, and no cleanup is
required. Halting is the same as doing endprocess in task manager. Everything
will be wiped clean to the operating system capability. Unsaved stuff is lost
etc etc.<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'>Halt is generally not an ideal way to kill
off an application. <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'>The help is from <st1:place w:st="on">Delphi</st1:place>
7 hlp. After Delphi 7 IMHO the help is pathetic and useless. Even d7 is missing
help from older versions that was more relevant and useful. God knows who wrote
their help system, but he/she should be hit on the head.<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> Saturday, 20 May 2006 11:06
a.m.<br>
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName w:st="on">NZ
Borland Developers Group - <st1:place w:st="on">Delphi</st1:place> 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'>Dear Kyley,<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 color="#3366ff" face="Times New Roman"><span
style='font-size:12.0pt;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"</span></font><br>
<br>
Thats the sort of stuff I was looking for in the help systrem. Which version of
<st1:place w:st="on">Delphi</st1:place> (help) was that in?<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>So far I have not found it in D2005.<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 color="#3366ff" face="Times New Roman"><span
style='font-size:12.0pt;color:#3366FF'>"As per the help file, which it
seems many have not read.. "</span></font><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>You say that Finalization does not happen on halt.<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'>Is there anything that can be caused to do cleanup if halt is executed?
Or is it utterly final?<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'>Paul<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><span class=gmailquote><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>On 20/05/06, <b><span style='font-weight:bold'>Todd
Martin</span></b> <<a href="mailto:toddm@kol.co.nz">toddm@kol.co.nz</a>>
wrote:</span></font></span> <o:p></o:p></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>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: "<st1:PersonName w:st="on">NZ Borland Developers Group - Delphi List</st1:PersonName>"
<<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: <st1:PersonName w:st="on">NZ Borland Developers Group - <st1:place
w:st="on">Delphi</st1:place> List</st1:PersonName><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 <st1:place w:st="on">Delphi</st1:place>
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>
> <st1:place w:st="on">Delphi</st1:place> 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>
> <st1:place w:st="on">Delphi</st1:place> 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>
<st1:place w:st="on">Delphi</st1:place> 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><o:p></o:p></span></font></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>
</body>
</html>