473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Inheritance


HI guys,

I am developing an application using c# sharp.I have a base form and all
other forms inherits from the base form.

all was running so well until i was given the task to find out which
inherited form is actually being used.

i.e i have a button in my base form and on clicking that button i want to
know which child is accessing the base form currently..

Please if this is possible then let me know ....

Lots of thanks in advance.
--
Regards
Soobrassen
Thoplan
Nov 22 '06 #1
5 2148
If this is inheritance, then you should just be able to call GetType(); this
should return the type of the derived class, not the base class.

Does this suffice?

Marc
Nov 22 '06 #2
You're not being really clear about what you would like to do. Inherritance
is more of a design time property. When the forms are generated at run-time,
their properties are inherrited by the parent object. If you are trying to
see if the children are properly connected to the base form try

ChildForm.Parent.Name

This will give you the name of the parent of the child form.
"Soobrassen Thoplan" wrote:
>
HI guys,

I am developing an application using c# sharp.I have a base form and all
other forms inherits from the base form.

all was running so well until i was given the task to find out which
inherited form is actually being used.

i.e i have a button in my base form and on clicking that button i want to
know which child is accessing the base form currently..

Please if this is possible then let me know ....

Lots of thanks in advance.
--
Regards
Soobrassen
Thoplan
Nov 22 '06 #3

As another posted said you can use this.GetType() to find out the
instantiated type. However, I would be very wary of any behavior that
depended on this type of setup as it sounds like it'll be a
maintenance hassle down the road and certainly be very confusing.

If you need the child forms to do somethign special then create a
virtual method, for example:
private void closeButton_Click(object sender, EventArgs e) {
OnBeforeCloseClick();
.. do something
OnAfterCloseClick();
}

protected virtual void OnBeforeCloseClick() {
// for extension
}

proteced virtual void OnAfterCloseClick() {
// for extension
}

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Wed, 22 Nov 2006 01:32:01 -0800, Soobrassen Thoplan
<so*****@yahoo.comwrote:
>
HI guys,

I am developing an application using c# sharp.I have a base form and all
other forms inherits from the base form.

all was running so well until i was given the task to find out which
inherited form is actually being used.

i.e i have a button in my base form and on clicking that button i want to
know which child is accessing the base form currently..

Please if this is possible then let me know ....

Lots of thanks in advance.
Nov 22 '06 #4

The Parent property is related to the composition relationship between
controls--which form or control contains the target control. There is
no correlation between the Parent property and the inheritance chain.

Inherittance is used at both design and runtime and it crucial to how
..NET works, especially forms and controls.

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Wed, 22 Nov 2006 03:47:01 -0800, Andrew McNab <Andrew
Mc***@discussions.microsoft.comwrote:
>You're not being really clear about what you would like to do. Inherritance
is more of a design time property. When the forms are generated at run-time,
their properties are inherrited by the parent object. If you are trying to
see if the children are properly connected to the base form try

ChildForm.Parent.Name

This will give you the name of the parent of the child form.

Nov 22 '06 #5
Yes, as Neff says. I think it would be better to put the special
implementation in the derived class. That is what it is for, afterall, and
the base class can't really be aware of all future possible derived classes
as that would make the encapsilation a bit hairy.

--
Thanks
Jonny
"Samuel R. Neff" wrote:
>
As another posted said you can use this.GetType() to find out the
instantiated type. However, I would be very wary of any behavior that
depended on this type of setup as it sounds like it'll be a
maintenance hassle down the road and certainly be very confusing.

If you need the child forms to do somethign special then create a
virtual method, for example:
private void closeButton_Click(object sender, EventArgs e) {
OnBeforeCloseClick();
.. do something
OnAfterCloseClick();
}

protected virtual void OnBeforeCloseClick() {
// for extension
}

proteced virtual void OnAfterCloseClick() {
// for extension
}

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Wed, 22 Nov 2006 01:32:01 -0800, Soobrassen Thoplan
<so*****@yahoo.comwrote:

HI guys,

I am developing an application using c# sharp.I have a base form and all
other forms inherits from the base form.

all was running so well until i was given the task to find out which
inherited form is actually being used.

i.e i have a button in my base form and on clicking that button i want to
know which child is accessing the base form currently..

Please if this is possible then let me know ....

Lots of thanks in advance.

Nov 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
4
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that...
5
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
10
by: davidrubin | last post by:
Structural inheritance (inheriting implementation) is equivalent to composition in that a particular method must either call 'Base::foo' or invoke 'base.foo'. Apparantly, The Literature tells us to...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
6
by: Bart Simpson | last post by:
I remember reading on parashift recently, that "Composition is for code reuse, inheritance is for flexibility" see (http://www.parashift.com/c++-faq-lite/smalltalk.html#faq-30.4) This confused...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.