Board index » delphi » Multiple use of single instance accross multiple machines

Multiple use of single instance accross multiple machines

Hello,

If you don't mind me asking:

Is there a way to have one instance of a COM object to be used by multiple
machines/applications? (dcom?)

My programming environments are Borland Delphi 4 (and VB6)

Erik Tamminga
etammi...@starren.nl

 

Re:Multiple use of single instance accross multiple machines


Hi Erik,

Do you really mean can you create a singleton COM object?  If so then the
answer is yes, although how you achieve this in the Delphi framework is
questionable.   It is recommended (esp for DCOM implementation) to create
multiple object instances, but each instance uses the same object data.
This allows for load-balancing, better garbage collection etc.

The long and short of it is that yes you can create a singleton - how you do
it is down to one of two means:

1. Override IClassFactory to return the same instance pointer (*not so good)
2. Implement multiple objects using the same data

*If you override CreateInstance in the IClassFactory, to return the same
instance pointer, then you will be violating the laws of COM - the semantics
of the of interface (the contract) is violated, since the user expects
CreateInstance to create a new instance, all the time.

Nick.

Quote
Erik Tamminga <etammi...@starren.nl> wrote in message

news:7umkar$s6n2@forums.borland.com...
Quote
> Hello,

> If you don't mind me asking:

> Is there a way to have one instance of a COM object to be used by multiple
> machines/applications? (dcom?)

> My programming environments are Borland Delphi 4 (and VB6)

> Erik Tamminga
> etammi...@starren.nl

Re:Multiple use of single instance accross multiple machines


Isn't there a COM way to implement the way MS Word works.

When using word, you can say:

    // Create a word object
    Word := CoApplication.Create;
    Word.Visible := True

and later on for example in a VB Application say

    Set Word = GetObject(, "Word.Application")
    Word.Visible = False

This returns a pointer to the same instance of word as created in the first
application. The first app displays word, the second app hides word.

Erik

Quote
Nicholas Robinson <NicholasRobin...@yahoo.co.uk> wrote in message

news:7umm22$s713@forums.borland.com...
Quote
> Hi Erik,

> Do you really mean can you create a singleton COM object?  If so then the
> answer is yes, although how you achieve this in the Delphi framework is
> questionable.   It is recommended (esp for DCOM implementation) to create
> multiple object instances, but each instance uses the same object data.
> This allows for load-balancing, better garbage collection etc.

> The long and short of it is that yes you can create a singleton - how you
do
> it is down to one of two means:

> 1. Override IClassFactory to return the same instance pointer (*not so
good)
> 2. Implement multiple objects using the same data

> *If you override CreateInstance in the IClassFactory, to return the same
> instance pointer, then you will be violating the laws of COM - the
semantics
> of the of interface (the contract) is violated, since the user expects
> CreateInstance to create a new instance, all the time.

> Nick.

> Erik Tamminga <etammi...@starren.nl> wrote in message
> news:7umkar$s6n2@forums.borland.com...
> > Hello,

> > If you don't mind me asking:

> > Is there a way to have one instance of a COM object to be used by
multiple
> > machines/applications? (dcom?)

> > My programming environments are Borland Delphi 4 (and VB6)

> > Erik Tamminga
> > etammi...@starren.nl

Re:Multiple use of single instance accross multiple machines


Erik,

That does work, but remember it is only for the same machine.  It simply
looks in the Running Object Table and returns the last recorded object you
ask for.  I am not aware of a way of doing this for a remote machine, but
irrespective of that you will need to make sure that your model works
without the use of GetObject - how do you know you clients will always call
GetObject? The normal way is CreateCOMObject/CreateRemoteCOMObject etc...

Just a thought....

Nick.

Quote
Erik Tamminga <etammi...@starren.nl> wrote in message

news:7umokm$s6s7@forums.borland.com...
Quote
> Isn't there a COM way to implement the way MS Word works.

> When using word, you can say:

>     // Create a word object
>     Word := CoApplication.Create;
>     Word.Visible := True

> and later on for example in a VB Application say

>     Set Word = GetObject(, "Word.Application")
>     Word.Visible = False

> This returns a pointer to the same instance of word as created in the
first
> application. The first app displays word, the second app hides word.

> Erik

> Nicholas Robinson <NicholasRobin...@yahoo.co.uk> wrote in message
> news:7umm22$s713@forums.borland.com...
> > Hi Erik,

> > Do you really mean can you create a singleton COM object?  If so then
the
> > answer is yes, although how you achieve this in the Delphi framework is
> > questionable.   It is recommended (esp for DCOM implementation) to
create
> > multiple object instances, but each instance uses the same object data.
> > This allows for load-balancing, better garbage collection etc.

> > The long and short of it is that yes you can create a singleton - how
you
> do
> > it is down to one of two means:

> > 1. Override IClassFactory to return the same instance pointer (*not so
> good)
> > 2. Implement multiple objects using the same data

> > *If you override CreateInstance in the IClassFactory, to return the same
> > instance pointer, then you will be violating the laws of COM - the
> semantics
> > of the of interface (the contract) is violated, since the user expects
> > CreateInstance to create a new instance, all the time.

> > Nick.

> > Erik Tamminga <etammi...@starren.nl> wrote in message
> > news:7umkar$s6n2@forums.borland.com...
> > > Hello,

> > > If you don't mind me asking:

> > > Is there a way to have one instance of a COM object to be used by
> multiple
> > > machines/applications? (dcom?)

> > > My programming environments are Borland Delphi 4 (and VB6)

> > > Erik Tamminga
> > > etammi...@starren.nl

Other Threads