Private mReference As String
Public Property Let Reference(Value As String)
mReference = Value
Public Property Get Reference() As String
Reference = mReference
Private Sub Class_Initialize()
mReference = ""
Private Sub Command1_Click()
Dim el As CEnclosures
Dim e As CEnclosure
Set w = New CWorkflow
w.Info = "Info" 'Here 1 message box is displayed since one event is fired from CWorkflow
Set el = w.Enclosures
Set e = el.Add(3, "Enclosur") 'Here 2 message boxes are displayed
'since 2 events are fired: one from CEnclosure and
'one from CEnclosures
e.Reference = "Enclosure" 'Here 1 message box should be displayed but it is not
'because no event is fired
Private Sub w_GotDirty()
09-19-2005, 03:08 PM
I believe this is what is happening.
In CEnclosures, you declare a CEnclosure with events, and you add it to the collection. But then you set it to nothing, so at this points the object still exists because it is still referenced by the Collection, but has lost the Sync interface that allows the event to be fired.
In situations like this (it is the same in an array of objects, not only a Collection) one solution is to add an extra class that raises the event, and pass it around:
Public event MyEvent()
public sub RaiseMyEvent()
Create one instance withevents of this class in CEnclosures:
private withevents m_c as CEventSync
private sub m_c_MyEvent()
and pass this class to each of the created CEnclosure objects. In CEnclosure, keep a reference of this class in a private variable then, instead of raising the event, call the RaiseMyEvent method of this new class.
This is just one method, and it is the one I prefer because it does not create any circular reference and does not need any global object.