473,385 Members | 1,356 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.

"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 1303
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.