Results 1 to 3 of 3

Thread: reference obects to each other - bit problem :-(

  1. #1

    Thread Starter
    Hyperactive Member fabianus's Avatar
    Join Date
    Sep 2004
    Location
    Paris
    Posts
    402

    Question reference obects to each other - bit problem :-(

    I have a class called "Class1" and a class "Class2".

    I want to create an instance of each and reference them to each other.

    So what I do is:

    VB Code:
    1. Public Class Class1
    2.     Dim myClass2 as new Class2
    3.  
    4.     Sub new ()
    5.         myClass2.set_myClass1(Me)
    6. End Sub
    7.  
    8. End Class
    9.  
    10. Public Class Class2
    11.     Dim myClass1 as new Class1
    12.  
    13.     Public Function set_myClass1 (ByRef myObject as Class1)
    14.         myClass1 = myObject
    15. End Function
    16. End Class

    So the problem is that once I did myClass2.set_myClass1(Me) in Class1 the instance of Class1 is not referenced, but copied in Class2. So if I make any changes in the instance of Class1, the myClass1 in Class2 does not change!

    Thank you very much for any advice as this is a major problem for my application.

    Just for the story: in fact I need this to create a general "persistancyObject", that saves Objects to a relational db. If anybody is interested in this – or even could give some critic, your welcome and I'll post the code. But it is a bit complicate as you'll see…

    Anyway, if someone could help me with the upper referencing problem, I would be more than glad!

    Regards,
    Fabian

  2. #2
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: reference obects to each other - bit problem :-(

    I don't know what all behind this, but i'll suggestion you to declare all your Class in a module and handle them there. Without cross referencing it from the inside of each class ...
    Using VS 2010 on Fw4.0

  3. #3
    Fanatic Member
    Join Date
    May 2002
    Posts
    746

    Re: reference obects to each other - bit problem :-(

    Looks like you're creating a new instance of Class1 in class2. Try dimming class1 w/o the new operator.

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