Just back in the basics where I am for a moment,
 
This is some code I found following a link that Stefan suggested in another thread today.
What is the benefit of doing it all in initialization and finalization  if it were contained in a form unit (which it was not incidentily)?
 
initialization
  begin
    TComObjectFactory.Create(ComServer, TOurNSHandler, Class_OurNSHandler,
      'OurNSHandler', 'OurNSHandler', ciMultiInstance, tmApartment);

    Table := TTable.Create(nil);
    table.DatabaseName := ExtractFilePath(Application.ExeName);
    table.TableName := DatabaseFile;
    table.active := true;
  end;

finalization
  table.free;



 
On 23/05/06, Karl @ Work <[EMAIL PROTECTED] > wrote:
> I'm curious as to why each of your consuming units needs to keep a
> reference to the singleton?
>
> IMHO, surely the whole point about a singleton is that you don't keep
> references per se to it.
>
> When you need to access the singleton, you should just call your
> Singleton function declared in your MySingletonUnit unit?
>
> Surely that would result in a whole lot less reference counting, and
> worrying about who's holding on to it and when they drop their
> references, etc.

I would prefer not to keep references to the singleton in the consuming
units, it's just that I haven't found another way to ensure that it will
free itself both (a) after everything else has finished using it and (b)
before the program finishes.  The problem is that the singleton can't be
cleaned up in the finalization of its own unit because there are still
references to it which are accessed after that.

Cheers,
Carl

_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi



_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to