|
-
Aug 6th, 2003, 11:13 PM
#1
Thread Starter
Hyperactive Member
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?
-
Aug 7th, 2003, 03:57 AM
#2
Lively Member
You need to declare it public or friend. (The sub)
HTH
-
Aug 7th, 2003, 06:47 AM
#3
Addicted Member
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.
-
Aug 7th, 2003, 12:00 PM
#4
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|