Creating Parent property for a custom class 
Author Message
 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



Mon, 12 Dec 2005 03:44:27 GMT  
 Creating Parent property for a custom class

purchase, read and love the VBA Developer's Hnadbook - available from
Sybex.


Quote:
>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

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.

Products:   http://www.geocities.com/word_heretic/products.html
Spellbooks: 735 pages of dump left and dropping...

The VBA Beginner's Spellbook: For all VBA users.



Wed, 14 Dec 2005 10:04:14 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Exposing Properties collection in custom classes as many MS Classes do

2. Exposing a Properties collection in custom classes as many MS Classes do

3. Properties Property for a Custom Class

4. Custom Property Designers and Parent objects?

5. Accessing Custom Properties in Forms -- Parent and Child ?

6. Creating properties of custom properties?

7. Parent Property for Classes

8. Can you access parent class properties?

9. Class / Parent.Parent /NameSpace

10. Creating a Parent Property

11. custom class collection (property)

12. Creating a custom Data Control/Class

 

 
Powered by phpBB® Forum Software