
Creating Parent property for a custom class
Howdy All,
I working on a system that will contain a number of
custom classes arranged in a heirarchy. All of these
classes should have a "Parent" property to permit
navigating up the heirarchy. However, my approach causes
Word to terminate with a page fault. The simplest code
that reproduces the problem contains just three classes:
IAbstractClass:
an abstract class with a property Set and property Get for
the "Parent" property
ConcreteClass:
an implementation of the IAbstract class, which either
returns a pointer to the Parent on "Get" (from a module
level variable) or that establishes the pointer on "Set".
It also raises an OnNewParent event in the "Set"
MyParentClass:
This class module contains just a single declaration, in
which "mcccConcrete" is declared as ConcreteClass
The problem arises in the MyParentClass. When I go to the
object box and select "mcccConcrete" hoping to write code
for the OnNewParent event. Word terminates, and
the "details" button reveals that the termination occured
in either winword.exe (sometimes in VBE6.exe)
The full text of the code is below. I'm running Windows
98 and Word 2000. I doubt that it is a virus, because it
occurs when I type it in on other computers running Word
2000. Thanks!
IAbstract:
Option Explicit
Public Property Set Parent(ByRef myp As MyParentClass)
End Property
Public Property Get Parent() As MyParentClass
End Property
ConcreteClass:
Option Explicit
Implements IAbstract
Public Event OnNewParent(ByRef strParentMsg As String)
Private myp As MyParentClass
Private Property Get IAbstract_Parent() As MyParentClass
Set IAbstract_Parent = myp
End Property
Private Property Set IAbstract_Parent( _
ByRef rmypPassed As MyParentClass)
Set myp = rmypPassed
RaiseEvent OnNewParent("A new parent has been set")
End Property
MyParentClass:
Option Explicit
Private WithEvents mcccConcrete As ConcreteClass