View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] hooksie2@hotmail.com is offline
external usenet poster
 
Posts: 35
Default Ensure single class instance but with multiple references to it

Okay - Now I'm with you. That's why you commented about future lazy
programmers - they might set a reference to my Public x directly rather
than going through my class object (?). If that's the only concern
it's not so bad since I will distribute the code as an xla and make
that module private so it's only my own laziness that I have to watch
out for.

Re my obvious confusion over variable scope. My thinking was:

Set m_objMyNewRef = GetOpenServer() - GetOpenServer() - Set
m_objOpenServer = OpenServerClass object, Set GetOpenServer() =
m_objOpenServer
So now there is a pointer from m_objMyNewRef to m_objOpenServer and
from m_objOpenServer to the actual OpenServer class

Now when I do, Set m_objOpenServer = Nothing, m_objMyNewRef is still
pointing to m_objOpenServer (or so I thought) so m_objOpenServer
wouldn't be destroyed. It seems the reference though is direcly from
m_objMyNewRef to the OpenServer class.

As I write this I've remembered something along these lines in the vba
developers handbook - will have to read again tonight. Caught out by
my own wishful thinking...

Once again thanks - I will go with your proposed solution.

Best Regards,
Andrew