<div>Just back in the basics where I am for a moment,</div>
<div>&nbsp;</div>
<div>This is some code I found following a link that Stefan suggested in another thread today. </div>
<div>What is the benefit of doing it&nbsp;all in <strong>initialization</strong> and <strong>finalization</strong>&nbsp;&nbsp;if it were contained in a form unit (which it was not incidentily)? </div>
<div>&nbsp;</div>
<div>initialization<br>&nbsp; begin<br>&nbsp;&nbsp;&nbsp; TComObjectFactory.Create(ComServer, TOurNSHandler, Class_OurNSHandler,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'OurNSHandler', 'OurNSHandler', ciMultiInstance, tmApartment);</div>
<div>
<p>&nbsp;&nbsp;&nbsp; Table := TTable.Create(nil);<br>&nbsp;&nbsp;&nbsp; table.DatabaseName := ExtractFilePath(Application.ExeName);<br>&nbsp;&nbsp;&nbsp; table.TableName := DatabaseFile;<br>&nbsp;&nbsp;&nbsp; table.active := true;<br>&nbsp; end;</p>
<p>finalization<br>&nbsp; table.free;</p><br><br>&nbsp;</div>
<div><span class="gmail_quote">On 23/05/06, <b class="gmail_sendername">Karl @ Work</b> &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:karlreynolds@xtra.co.nz" target="_blank">karlreynolds@xtra.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">&gt; I'm curious as to why each of your consuming units needs to keep a<br>&gt; reference to the singleton? 
<br>&gt;<br>&gt; IMHO, surely the whole point about a singleton is that you don't keep<br>&gt; references per se to it.<br>&gt;<br>&gt; When you need to access the singleton, you should just call your<br>&gt; Singleton function declared in your MySingletonUnit unit? 
<br>&gt;<br>&gt; Surely that would result in a whole lot less reference counting, and<br>&gt; worrying about who's holding on to it and when they drop their<br>&gt; references, etc.<br><br>I would prefer not to keep references to the singleton in the consuming 
<br>units, it's just that I haven't found another way to ensure that it will<br>free itself both (a) after everything else has finished using it and (b)<br>before the program finishes.&nbsp;&nbsp;The problem is that the singleton can't be 
<br>cleaned up in the finalization of its own unit because there are still<br>references to it which are accessed after that.<br><br>Cheers,<br>Carl<br><br>_______________________________________________<br>Delphi mailing list 
<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Delphi@ns3.123.co.nz" target="_blank">Delphi@ns3.123.co.nz</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://ns3.123.co.nz/mailman/listinfo/delphi" target="_blank">
http://ns3.123.co.nz/mailman/listinfo/delphi</a><br><br><br></blockquote></div><br>