|
I'm a bit confused at something...
Look at this code:
((ISupportInitialize)(this.trackBar)).EndInit();
There is no significance to this particular code, it's just an example.
trackBar is an object that implements the ISupportInitialize interface. That interface only defines BeginInit() and EndInit().
Questions:
1. trackBar does NOT implement these methods at all - how come this is allowed? Obviously ISupportInitialize doesn't implement them either, as it is an interface.
2. How can we cast from trackBar to ISupportInitialize and call a method with no implementation?
What is going on? Also, why cast at all if trackBar1 DID implement them?
Also, when you do cast from an object that implements interface X, does that new casted object only contain the methods that X defines?
I'm ashamed to not know this - and I'm sure it'll be very clear, but it's just going against the grain to what I know.
Thanks,
Cormac
|
|
|
|
|
Cormac M Redmond wrote: trackBar does NOT implement these methods at all - how come this is allowed?
I don't think it is allowed.
I would say it should throw you an InvalidCastException.
How does your TrackBar class declaration looks like?
Cormac M Redmond wrote: Also, when you do cast from an object that implements interface X, does that new casted object only contain the methods that X defines?
Yes. Boxing to a base class/interface hides the members of the derived class.
|
|
|
|
|
Hi,
It is allowed though - I found it it fully working code.
Here it is also:
http://msdn2.microsoft.com/en-us/library/system.componentmodel.isupportinitialize.aspx
It's really wrecking my head
Regards,
Cormac Redmond
|
|
|
|
|
Well... I thought that TrackBar is a class you created.
After finding out it's located in System.Windows.Forms I checked its base types.
If you open your Object Browser and do the same you'll see that TrackBar DOES implement ISupportInitialize .
Regards,
Shy.
|
|
|
|
|
That was a poor example then - the code I have in a project does NOT implement them.
And if you're write about TrackBar...why cast to the interface? Why not just call the methods?
Regards,
Cormac
|
|
|
|
|
imho you can cast an object to an interface even the methods aren't implemented. the code will compile. but if the runnig programm tries to execute this, you will get an System.InvalidCastException.
cheers
|
|
|
|
|
|
shyagam wrote: Yes. Boxing to a base class/interface hides the members of the derived class.
Boxing means accessing a value type via a reference. What you wanted to say is "casting". The two are different concepts, although boxing happens at the same time as a value type is cast to the base type.
|
|
|
|
|
Hmm... I see...
I'll remember that.
|
|
|
|
|
Cormac M Redmond wrote: trackBar does NOT implement these methods at all
What makes you think that? Here they are:
TrackBar.BeginInit[^]
TrackBar.EndInit[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Cormac M Redmond wrote: Also, when you do cast from an object that implements interface X, does that new casted object only contain the methods that X defines?
The object doesn't change. After you cast an object it is still the same object. It is just the reference to it that is different.
|
|
|
|
|
Sorry....I knew that - not being very clear today.
|
|
|
|
|
No problem - we all have days like that from time to time.
Earlier this week I sent an email round the development team at work telling them about this work around I'd found to get around the fact that such-and-such menu item wasn't available in a certain project type in Visual Studio. One of the devs in our other office wrote back and said, "do you mean the 8th item on the so-and-so menu?". For a whole day I'd been ripping my hair out trying to figure it out and it was staring at me in the face. I replied the only thing I could reply: "This year I shall be mostly going slightly mad".
Also, in my uni' days I'd rip my hair out over compiler messages that I couldn't understand. I'd eventually find after several hours I'd missed a semi-colon. Luckily, today compilers are much better about point out missing semi-colons than the DOS version of Turbo C++ was.
|
|
|
|
|
((ISupportInitialize) this.pictureBox1).BeginInit();
Ok...there pictureBox1 is a PictureBox and does not implement those methods.
Can anyone explain?
My first example was a bad one.
Regards,
Cormac
|
|
|
|
|
In Framework 2.0 PictureBox implements both methods as explicit interface implementations; scroll down to the bottom of the following page:
PictureBox Methods[^].
Some information on explicit interface implementations can be found here: Explicit interface member implementations[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Excellent - question answers.
Thanks.
|
|
|
|
|
hi everyone, anyone, just be kind enough and tell me how the h*** am i supposed to edit my article in an easy way, what makes me go mad about this, is that it's the forth article im posting here and the first to be problematic!! please help.
Pointless Game
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Well, this isn't the right place to ask this. Are you saying that you don't have a link to edit it ? I think it's the case that once an article is edited by one of our editors, you can no longer edit it, you need instead to email the edited text as a submission. That's my recollection. If you can provide some more details, perhaps I can help further.
Nope - all your articles are unedited. Which one is the problem ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
thank you Graus, actually, it's not editing, it's posting!!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Muammar© wrote: actually, it's not editing, it's posting!!
Do you mean that you want to post a brand new article?
|
|
|
|
|
thank you guyz, actually im just fed up with it, i guess im leaving it as it is now
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
there is a Get Article's HTML link on top of your article save the source and then upload it again
I Wish the Life Had CTRL-Z
|
|
|
|
|
thanx, i'll give it a shot.
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
I was wondering if someone could help me with a little problem
I have a large multiline text box (8000 characters long) called txtComments, above it a button called btnSelectAll.
What I have been trying to do is, when the user clicks the button the text in the multiline text box is all highlighted.
This is part of a ASP.Net web project using C#
Many thanks for your help
Subduction37
|
|
|
|
|
subduction36 wrote: This is part of a ASP.Net web project using C#
So, you want to find some javascript that will select all the text ?
This[^] seems to cover it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|