Results 1 to 4 of 4

Thread: Class Question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382

    Class Question

    Ok I need some help... Here's my question..

    I have 2 Classes..

    ClassA and ClassB

    ClassA has a instance of class B declared in it..

    ClassA
    CB As ClassB
    .......
    Sub Whatever
    End Class

    Ok I need to know if there is anyway to Access "Sub Whatever" in ClassA from inside the instance of CB (ClassB).

    My problem is ClassB is a child socket class, and when the socket receives data and it's receive data event fires, I need to be able to access the parent class's routines without having a actual reference address to the parent that contains the socket class. I though MyBase would do it but it doesn't seem to.. Can anyone offer any insight on how to call a parents routines from a child instance?

  2. #2
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    You need to declare it public or friend. (The sub)

    HTH

  3. #3
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    mybase keyword only works if there is an inheritence relationship between classes ie. ClassB 'is-a' ClassA. What it LOOKS like you have here is a 'has-a' realtionship ie. ClassA has a ClassB delared within. I am guessing this cause you dont mention if you are inheriting classes although you do mention a parent-child setup ??!!...put me right if i am off the mark

    To answer your question - ClassB does not know about the existence of ClassA and therefore you cant call ClassA methods from ClassB directly. You need to get a ClassA object reference for ClassB to become 'aware' of it...

    if you made ClassA a shared (or even wrote an additional [shared] notifier class to manage method calls between instance objects) it would work but you would have to account for threadsafety etc. etc. (if thats important for you)

    Any use to ya?

    Cheers...
    Last edited by powdir; Aug 7th, 2003 at 06:51 AM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    Originally posted by powdir
    mybase keyword only works if there is an inheritence relationship between classes ie. ClassB 'is-a' ClassA. What it LOOKS like you have here is a 'has-a' realtionship ie. ClassA has a ClassB delared within. I am guessing this cause you dont mention if you are inheriting classes although you do mention a parent-child setup ??!!...put me right if i am off the mark

    To answer your question - ClassB does not know about the existence of ClassA and therefore you cant call ClassA methods from ClassB directly. You need to get a ClassA object reference for ClassB to become 'aware' of it...

    if you made ClassA a shared (or even wrote an additional [shared] notifier class to manage method calls between instance objects) it would work but you would have to account for threadsafety etc. etc. (if thats important for you)

    Any use to ya?

    Cheers...

    Yes ClassA doesn't inherit ClassB but just just holds an instance of it. So you're saying I either have to do a direct Inheritance OR pass a ClassA reference to ClassB to be able to access ClassA's routines?

    And yes thread safety is an issue.. The asyncrounous socket server I wrote is complete, when a Client connects, it fires a Connect event that passes a new SocketState class I wrote through an event. This is where I declare a Instance of a ClientData class and I stick a copy of the passed socket class inside the ClientData class.. Do you see where my problem is?


    ClientData>SocketData

    It's basically a backwards hierarchy and since the socket class can fire event froms outside influence, I need to be able to reference the ClientData class that holds the SockeState class..

    Ah well I guess I will figure something out.. I guess I can have the ClientData class Inherit the SocketState class but that seems a bit of a overkill..

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