Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Yet another C# WTF moment: UserControls

  • 11-11-2004 12:43PM
    #1
    Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭


    So, I'm developing some userControls as part of something I'm building. They're kinda neat really. Here's the thing though....

    A lot of these controls have common functionality. SO I thought I'd be smart, and define a BaseParameterControl, and then derive my various XParameterControl classes from it. So far so good. OK - I have to have a no-parameter constructor, which I don't really want, but I can live with that.

    Then I discovered a really cool shortcut I could take if I had some abstract members implemented in the base control....so I set it to abstract, add the abstract method signatures...compile...all looks fine.

    Then I try opening a *derived* class in teh designer. That doesn't work. Nope. It tells me that it failed because it couldn't create an instance of hte base control, cause its abstract. Seems a bit stupid, but hey...

    However...

    if I try opening the *abstract* class in the designer, guess what....it opens just fine.

    OK. Screw it. I can live with this...I'll just de-abstract my base class, and implement an interface across all of the derived ones. That solves that...as long as I forget to think *why* this might be happening.

    Next trick....I decide to add an event. So, I declare it in the base class. But guess what...this means I can't raise it in the derived class!!! Again, some WTFness ensues, and eventually I give up, wrap the call to the event in a method which does nothing except raise the event....and *this* I can call from the derived class without problems...

    If anyone knows *why* this behaviour is correct/necessary...I'd be interested....

    jc


Comments

  • Registered Users, Registered Users 2 Posts: 2,157 ✭✭✭dazberry


    bonkey wrote:
    Then I discovered a really cool shortcut I could take if I had some abstract members implemented in the base control....so I set it to abstract, add the abstract method signatures...compile...all looks fine.

    Then I try opening a *derived* class in teh designer. That doesn't work. Nope. It tells me that it failed because it couldn't create an instance of hte base control, cause its abstract. Seems a bit stupid, but hey...

    However...

    if I try opening the *abstract* class in the designer, guess what....it opens just fine.

    Although this is essentially a joke - look at warning #7
    http://www.bbspot.com/News/2004/11/top_11_c_sharp_compiler_warnings.html


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Lol.

    As an aside...I've also noticed that my compiler gives me warnings on three forms where there's a variable thats never initialised.

    The variable? The System.ComponentModel.Container components one, which the designer insists is absolutely, positively needed.

    Fscking thing.


Advertisement