Board index » delphi » TAutoObject and the Singleton pattern
Angelos Arampatzis
![]() Delphi Developer |
Sun, 09 Jun 2002 03:00:00 GMT
|
Angelos Arampatzis
![]() Delphi Developer |
Sun, 09 Jun 2002 03:00:00 GMT
TAutoObject and the Singleton pattern
What is the best way to have an automation object behave in the way
described by the Singleton pattern? In other words, what is the best way to make sure that there is only one globaly accessible instance of a given automation object? Thanks in advance _________________________________ The minimum could be defined as the perfection that an artifact achieves |
Yoram Halbersta
![]() Delphi Developer |
Sun, 09 Jun 2002 03:00:00 GMT
Re:TAutoObject and the Singleton patternMake your own factory (you need to subclass TAutoObjectFactory and reimplement IClassFactoy2.CreateInstanceLic). Dr. Delphi QuoteAngelos Arampatzis wrote: |
Andrew Jackso
![]() Delphi Developer |
Mon, 10 Jun 2002 03:00:00 GMT
Re:TAutoObject and the Singleton patternIt can be done this way, Binh Ly's excellent site (http://www.techvanguards.com/) has some sample code for doing so. However, from experience (it can become unreliable) I'd recommend a different approach.... Don't attempt to make the actual automation object a singleton. Instead, unit MyAutoObject; TMyAutoObject = class(TAutoObject, IMyAutoInterface) function TMyAutoObject .Method1 : HResult initialization unit MyDelphiObject; TMyDelphiObject = class(TObject); {implement this class as singleton} function TMyAutoObject .Method1 : HResult With this approach each client will create a new instance of TMyAutoObject Andrew QuoteYoram Halberstam <webmas...@netfever.com> wrote in message Quote> Make your own factory (you need to subclass TAutoObjectFactory and |
Scott Holma
![]() Delphi Developer |
Mon, 10 Jun 2002 03:00:00 GMT
Re:TAutoObject and the Singleton patternYou may also need to implement CreateInstance in your subclass. Here is a sample: type end; implementation uses Windows, ComServ, ComConst, uEMCommonUtility, SubscriptionEngine_TLB, {-------------------------------------------------------------------------- {-------------------------------------------------------------------------- function TMicrosEMStorageFactory.CreateInstance(const UnkOuter: IUnknown; {-------------------------------------------------------------------------- try except Result := FSingleton.ObjQueryInterface(IID, vObject); >Dr. Delphi >Angelos Arampatzis wrote: >> What is the best way to have an automation object behave in the way >> Thanks in advance >> _________________________________ >> The minimum could be defined as the perfection that an artifact achieves |
Yaniv Gola
![]() Delphi Developer |
Thu, 13 Jun 2002 03:00:00 GMT
Re:TAutoObject and the Singleton patternAngelos, Following is the text I posted a while ago, you might find it useful: --------------- ...................The two techniques you mentioned should work. However, The approach that works for me is the following: - Implement the COM server as a out-of-process (EXE) server. Let's call the var function IMyServerAccess.GetMyServer: IMyServer; The clients would use it in the following manner: MyServerAccess := CoMyServerAccess.CreateRemote(my-server-name) The lifespan of the access object is very short - once the server interface Because the Access object and the server object are in the same server, the Note that the actual implementation is a bit more complicated, because of enter critical section; Etc. If you need it, I can post the code that handles the switching between the ------------------------ I hope this helps, Yaniv Golan Quote"Angelos Arampatzis" <agge...@cteam.the.forthnet.gr> wrote in message Quote> What is the best way to have an automation object behave in the way |
1. Thoughts on the Singleton pattern - To Dave Shapiro
2. Thoughts on the Singleton design pattern
3. Q: Implementing the Singleton Design Pattern?
4. Singleton pattern reveals hole in Delphi privacy
5. Singleton pattern reveals hole in Delphi privacy - maybe
6. Singleton pattern worth it or not?
7. Singleton pattern variation
8. Can I Use the Singleton pattern to return a TADOConnection in COM+ Application?