Results 1 to 5 of 5

Thread: Problems working with tree structured classes....[Resolved]

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member techman2553's Avatar
    Join Date
    Mar 2001
    Location
    <- To your left.
    Posts
    362

    Problems working with tree structured classes....[Resolved]

    Hello,

    If you have a tree structure of classes, how can you access functions, ect. accross branches of the tree ??

    For example:

    If you have the following classes:

    ClassMain
    Class1
    Class2
    Class3
    ClassA
    ClassB
    ClassC

    And they are structured as two main branches:

    ClassMain.Class1.Class2.Class3
    and
    ClassMain.ClassA.ClassB.ClassC

    How can I easily access Properties or functions of ClassC from inside of Class3:

    VB Code:
    1. '******************
    2. '*** Class Main ***
    3. '******************
    4. Class clsClassMain
    5.     Public ClassA As New clsClassA()
    6.     Public Class1 As New clsClass1()
    7.  
    8.     Public Sub New()
    9.         Debug.WriteLine(ClassA.ClassB.ClassC.DoSomething(123))
    10.         Debug.WriteLine(Class1.Class2.Class3.SomethingNew(456))
    11.     End Sub
    12. End Class
    13.  
    14. '********************
    15. '*** First Branch ***
    16. '********************
    17. Class clsClassA
    18.     Public ClassB As New clsClassB()
    19. End Class
    20.  
    21. Class clsClassB
    22.     Public ClassC As New clsClassC()
    23. End Class
    24.  
    25. Class clsClassC
    26.     Public Function DoSomething(ByVal Value As Int16) As Int16
    27.         'Do something usefull with Value
    28.     End Function
    29. End Class
    30.  
    31. '*********************
    32. '*** Second Branch ***
    33. '*********************
    34. Class clsClass1
    35.     Public Class2 As New clsClass2()
    36. End Class
    37.  
    38. Class clsClass2
    39.     Public Class3 As New clsClass3()
    40. End Class
    41.  
    42. Class clsClass3
    43.     Public Function SomethingNew(ByVal Value As Int16) As Int16
    44.         'ClassMain can't be used here - what can I use to get the reference of the first branch ???
    45.         Return ClassMain.ClassA.ClassB.ClassC.DoSomething(Value) * 16
    46.     End Function
    47. End Class

    I know that I could manually pass object references into each brach, but is there a way to get a "Parent Class" reference ??


    Thanks for any help !!
    Last edited by techman2553; Oct 26th, 2003 at 04:28 PM.
    ----------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width