473,326 Members | 2,013 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,326 software developers and data experts.

"overclassing"

Hi

it's possible to "overclass" (at runtime) a base control with a new instance
of a derived class?

Thanks

Nov 16 '05 #1
4 1301
Tabulator <ta*******@tabuland.com> wrote:
it's possible to "overclass" (at runtime) a base control with a new instance
of a derived class?


What exactly do you mean? If you could give more explanation about what
you're trying to do, we might be able to help.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
I'm sorry but my english isn't so good...

An example:
I have a Button on a form (class Button)
In the project I have a control derived from Buttom (DerivedButton)

I need to use at runtime the button like it is a DerivedButton.

(In win32 is a kind of subclassing...)

"Jon Skeet [C# MVP]" <sk***@pobox.com> ha scritto nel messaggio
news:MP***********************@msnews.microsoft.co m...
Tabulator <ta*******@tabuland.com> wrote:
it's possible to "overclass" (at runtime) a base control with a new instance of a derived class?


What exactly do you mean? If you could give more explanation about what
you're trying to do, we might be able to help.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Tabulator <ta*******@tabuland.com> wrote:
I'm sorry but my english isn't so good...

An example:
I have a Button on a form (class Button)
In the project I have a control derived from Buttom (DerivedButton)

I need to use at runtime the button like it is a DerivedButton.

(In win32 is a kind of subclassing...)


You certainly can't treat an instance of just the base class as if it
were an instance of the derived class, no.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

"Tabulator" wrote ...
I have a Button on a form (class Button)
In the project I have a control derived
from Buttom (DerivedButton)

I need to use at runtime the button like
it is a DerivedButton.


You can in most cases not cast *down* from a superclass to a subclass, but
there's at least two other approaches you can use to solve this:

1. You can *replace* an initial Button
with a DerivedButton in runtime.

As an example, if you have a Button in your form, such as:

private Button myButton = new Button();

You can anytime during execution exchange that for an instance of a subclass
to Button, e.g. DerivedButton:

myButton = new DerivedButton();

(a variable of a supertype can reference to an instance of any of its
subtypes)

Just remember to do the rest of possibly needed initiation for the new
button, such as Location, EventHandlers, etc.

However, the most obvious and easiest approach is:

2. Use the DerivedButton from start!
I can't see any reason to why not, as the
DerivedButton inherits all of the behaviour
from Button.

// Bjorn A

Nov 16 '05 #5

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

Similar topics

4
by: Tabulator | last post by:
Hi it's possible to "overclass" (at runtime) a base control with a new instance of a derived class? Thanks
4
by: Tabulator | last post by:
Hi it's possible to "overclass" (at runtime) a base control with a new instance of a derived class? Thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.