Home All Groups Group Topic Archive Search About

Can a custom object know it's owner

Author
5 Oct 2006 11:34 AM
Usarian
I am making some custom objects that operate "inside" each other, the way a
datatable is available inside a dataset.  (VB.NET 1.1)
I can't figure out how to make the child object know what object it's inside
of.

What I have is a custom object called Ageload which contains a custom
collection designed to hold another custom object called a Batch.
(Ageload, BatchCollection, Batch)

When I use a dataset with a table in it, I can do something like:
Datatable.Dataset (and get a reference to the dataset and all of it's
functions/properties)

I want to make my Ageloads and Batches do the same thing:
Batch.Ageload (and get a reference to the Ageload)

Thanks!

Usarian

Author
5 Oct 2006 12:16 PM
Robinson
Simply store a reference to the object in the child object.  When you create
the child object, pass in the parent instance to initialize it.  i.e.:



Public Class ParentClass

End Class


Public Class ChildClass

    Private m_Parent As ParentClass = Nothing

    Public Readonly Property MyParent As ParentClass

        Get
            return m_Parent
        End Get

    End Property



    Public Sub New ( byval theParent As ParentClass )

        m_Parent = theParent

    End Sub

End Class

Show quoteHide quote
"Usarian" <noem***@nojunk.com> wrote in message
news:OM$LLJH6GHA.4276@TK2MSFTNGP04.phx.gbl...
>I am making some custom objects that operate "inside" each other, the way a
>datatable is available inside a dataset.  (VB.NET 1.1)
> I can't figure out how to make the child object know what object it's
> inside of.
>
> What I have is a custom object called Ageload which contains a custom
> collection designed to hold another custom object called a Batch.
> (Ageload, BatchCollection, Batch)
>
> When I use a dataset with a table in it, I can do something like:
> Datatable.Dataset (and get a reference to the dataset and all of it's
> functions/properties)
>
> I want to make my Ageloads and Batches do the same thing:
> Batch.Ageload (and get a reference to the Ageload)
>
> Thanks!
>
> Usarian
>
Author
5 Oct 2006 12:30 PM
Usarian
I might have to do it that way.   I'm already passing in about 6 values, and
wanted avoid making it any larger.  Collections are new to me, so I thought
that they might know who owns them.  (But the Batch itself still wouldn't
know it was in a collection anyway, so I'm still in the same boat.)

I have to wonder how they made the datatable know what dataset contains it
without passing that information in.


Anyway, Thanks!
Usarian


Show quoteHide quote
"Robinson" <toomuchspamhaspassed@myinboxtoomuchtoooften.com> wrote in
message news:eg2t2l$3fs$1$8300dec7@news.demon.co.uk...
>
> Simply store a reference to the object in the child object.  When you
> create the child object, pass in the parent instance to initialize it.
> i.e.:
>
>
>
> Public Class ParentClass
>
> End Class
>
>
> Public Class ChildClass
>
>    Private m_Parent As ParentClass = Nothing
>
>    Public Readonly Property MyParent As ParentClass
>
>        Get
>            return m_Parent
>        End Get
>
>    End Property
>
>
>
>    Public Sub New ( byval theParent As ParentClass )
>
>        m_Parent = theParent
>
>    End Sub
>
> End Class
>
> "Usarian" <noem***@nojunk.com> wrote in message
> news:OM$LLJH6GHA.4276@TK2MSFTNGP04.phx.gbl...
>>I am making some custom objects that operate "inside" each other, the way
>>a datatable is available inside a dataset.  (VB.NET 1.1)
>> I can't figure out how to make the child object know what object it's
>> inside of.
>>
>> What I have is a custom object called Ageload which contains a custom
>> collection designed to hold another custom object called a Batch.
>> (Ageload, BatchCollection, Batch)
>>
>> When I use a dataset with a table in it, I can do something like:
>> Datatable.Dataset (and get a reference to the dataset and all of it's
>> functions/properties)
>>
>> I want to make my Ageloads and Batches do the same thing:
>> Batch.Ageload (and get a reference to the Ageload)
>>
>> Thanks!
>>
>> Usarian
>>
>
>
Author
5 Oct 2006 1:05 PM
Robinson
> I have to wonder how they made the datatable know what dataset contains it
> without passing that information in.
>
>
> Anyway, Thanks!
> Usarian
>

You can be sure that information is passed through somewhere during
construction, perhaps behind the scenes.
Author
5 Oct 2006 6:33 PM
GhostInAK
Hello Usarian,

Override your collection class's Add and AddRange methods. 

-Boo

Show quoteHide quote
> I am making some custom objects that operate "inside" each other, the
> way a
> datatable is available inside a dataset.  (VB.NET 1.1)
> I can't figure out how to make the child object know what object it's
> inside
> of.
> What I have is a custom object called Ageload which contains a custom
> collection designed to hold another custom object called a Batch.
> (Ageload, BatchCollection, Batch)
>
> When I use a dataset with a table in it, I can do something like:
> Datatable.Dataset (and get a reference to the dataset and all of it's
> functions/properties)
>
> I want to make my Ageloads and Batches do the same thing:
> Batch.Ageload (and get a reference to the Ageload)
>
> Thanks!
>
> Usarian
>