From: Larry Serflaten on

"BeeJ" <nospam(a)live.com> wrote

> On exiting, in Class_Terminate I do
>
> Set cEntry = Nothing
>
> So that should decrement.


I would think not. The class that is terminating is cEntry.
In order for cEntry to terminate, all references to it have
to be realeased.

My point is, that at that point in time, cEntry should essentially
already be Nothing, so setting it to Nothing again, has no effect.

You did not show your class instantiation in your first post.
Where are you creating the first instance of that class?

LFS


From: BeeJ on
I use this in several places.

Case 1: the main form instantiates this.

Dim cEntry as Entry ' e.g. within a sub

Set cEntry = New Entry '

Case 2: the main app instantiates an ActiveX EXE using early binding.

Private WithEvents cEntry as Ax.Entry

Set cEntry = New Ax.Entry


Now I am working with Case 2.


From: ralph on
On Tue, 10 Aug 2010 07:51:30 -0700, BeeJ <nospam(a)live.com> wrote:

>I use this in several places.
>
>Case 1: the main form instantiates this.
>
> Dim cEntry as Entry ' e.g. within a sub
>
> Set cEntry = New Entry '
>
>Case 2: the main app instantiates an ActiveX EXE using early binding.
>
> Private WithEvents cEntry as Ax.Entry
>
> Set cEntry = New Ax.Entry
>
>
>Now I am working with Case 2.
>

Abandon 'thought experiments'.

Create a simple test suite, one client exe, one ActiveX exe. With one
object - MyClass.
Add a message/logger to the Initialize and Terminate events in
MyClass. It is also helpful to provide a static 'count'.
Duplicate the same basic calling/creating/destruction architecture,
but leave out the rest of the code.
(The VB Class Builder is very useful for generating this MyClass
object with 'debug' code.)
Then run it with both projects open and watch the sequence of events.
You are bound to be surprised.

You may need to move to a Proxy or Mediator pattern.

-ralph
From: Larry Serflaten on

"BeeJ" <nospam(a)live.com> wrote

> I use this in several places.
>
> Case 1: the main form instantiates this.
>
> Dim cEntry as Entry ' e.g. within a sub
>
> Set cEntry = New Entry '

Then, every time you call up a 'new' copy, the first thing it does
is this:

Private Sub Class_Initialize()
Set cEntry = Me ' to allow access from
' modules back to this class
Startup ' code in module
End Sub 'Class_Initialize

Which in effect wipes out the old instance in favor of the new.
Try this instead:

In the module (mdlEntry) where you have:

Public cEntry As Entry

Private Sub Msg(sMsg as String)
cEntry.StatusMsg sMsg
End Sub

Use this:

'============
Private mEntry As Entry

Private Sub Msg(sMsg as String)
cEntry.StatusMsg sMsg
End Sub

Public Property Get cEntry() As Entry
If mEntry Is Nothing then Set mEntry = New Entry
Set cEntry = mEntry
End Property

Public Sub CleanUp()
Set mEntry = Nothing
End Sub
'================

Then, you'll never need to create an instance, and you will
be gaurenteed to be be using only one instance. When its
time to close down, call the CleanUp routine to release that
one copy of Entry.


LFS








>
> Case 2: the main app instantiates an ActiveX EXE using early binding.
>
> Private WithEvents cEntry as Ax.Entry
>
> Set cEntry = New Ax.Entry
>
>
> Now I am working with Case 2.
>
>


From: BeeJ on
Thanks. That is very different and I will give it a try.