Is it Possible to get parent/container objects of other objects?

S

Sam Marrocco

If an object is the child of another object, is it possible to refer to
the parent's properties? Put simply (in pseudocode),

Public Class MyChild_Class
Public NameOfChild as string
End Class

Public Class MyParent_Class
Public NameOfParent As String
Public Child as MyChild_Class
End Class

dim a as MyParent_Class
a.NameOfParent="Dad"
a.NameOfChild="Billy"

Console.WriteLine(a.Child.PARENTOBJECTBASE.NameOfParent)

Ideally, I'd like something for PARENTOBJECTBASE that can refer to
whatever class is the "containing parent class" for my child object. I
suppose I'm looking for something similiar to MyBase (which only works
with classes that are *inherited*, which my class is *not*).

I'm trying *not* to have to include the parent info in each child if at
all possible, hence my quest for this method. Is it possible?
 
C

Cor Ligthert

Sam,

Except when it is a Top form class, in other cases you can just pass a
reference from the parent class in the contructor, and than all is done.
(With a topform you can set the parentform property).

I hope this helps?

Cor
 
S

Sam Marrocco

Cor said:
Sam,

Except when it is a Top form class, in other cases you can just pass a
reference from the parent class in the contructor, and than all is done.
(With a topform you can set the parentform property).


Cor,
The classes I'm attempting to use are not forms, merely class objects.
However, I do think that what you mention may be my solution, though.
Sending a reference to the child object is something that never occurred
to me. I will try this, thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top