Home All Groups Group Topic Archive Search About

Inheritance Question in VB.NET

Author
29 Mar 2005 5:25 PM
Saumitra
Hi
I am new to VB.NET and I am trying to figure out how to exchange data
between 2 forms based on parent-child relationship between 2 forms. Form2 is
child of form1. In form1.vb, I am doing
Dim t As New Form2
t.Show()

This is really strange to me because by OOPS, a base class has no knowledge
of the child class and should be able to instantiate a child class object.

Can someone explain this? Also, can someone suggest a better way to exchange
data between 2 forms.

Regards

Saumitra

Author
29 Mar 2005 5:33 PM
Supra
Dim t As New Form2
t.mdiparent = me
t.Show()



Saumitra wrote:

Show quoteHide quote
>Hi
>I am new to VB.NET and I am trying to figure out how to exchange data
>between 2 forms based on parent-child relationship between 2 forms. Form2 is
>child of form1. In form1.vb, I am doing
>Dim t As New Form2
>t.Show()
>
>This is really strange to me because by OOPS, a base class has no knowledge
>of the child class and should be able to instantiate a child class object.
>
>Can someone explain this? Also, can someone suggest a better way to exchange
>data between 2 forms.
>
>Regards
>
>Saumitra

>
Author
29 Mar 2005 5:38 PM
Robin Tucker
Ahhh, what you are talking about "parent<-->child" relationship between
forms is not the same as inheritance.  In OOP, inheritence refers to the
fact that the methods, properties and member variables of a class are
"inherited" by the new class at compile time, whereas the Window Parent <->
Child relationship purely refers to the fact that one recieves messages from
the other.  Your Form1 will contain a reference to your Form2 and your Form2
will contain a reference (parent) to your Form1.  Both of the classes you
are using are derived from Windows.Forms, not from each other.





Show quoteHide quote
"Saumitra" <Saumi***@discussions.microsoft.com> wrote in message
news:1416CD53-1930-4E6B-92AE-D9ECCAEF98E2@microsoft.com...
> Hi
> I am new to VB.NET and I am trying to figure out how to exchange data
> between 2 forms based on parent-child relationship between 2 forms. Form2
> is
> child of form1. In form1.vb, I am doing
> Dim t As New Form2
> t.Show()
>
> This is really strange to me because by OOPS, a base class has no
> knowledge
> of the child class and should be able to instantiate a child class object.
>
> Can someone explain this? Also, can someone suggest a better way to
> exchange
> data between 2 forms.
>
> Regards
>
> Saumitra
Author
29 Mar 2005 7:12 PM
Herfried K. Wagner [MVP]
"Saumitra" <Saumi***@discussions.microsoft.com> schrieb:
> I am new to VB.NET and I am trying to figure out how to exchange data
> between 2 forms based on parent-child relationship between 2 forms. Form2
> is
> child of form1. In form1.vb, I am doing
> Dim t As New Form2
> t.Show()
>
> This is really strange to me because by OOPS, a base class has no
> knowledge
> of the child class and should be able to instantiate a child class object.

Inheritance <> Parent <-> child relationship!

What you need is a reference to your instance of the form you want to
manipulate.  There are different ways to make this reference available, for
example, by passing it in method parameters or assigning it to properties,
or implementing the Singleton design pattern if there can be only one
instance of a form:

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>