Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Yet another C# WTF moment: UserControls

Options
  • 11-11-2004 12:43pm
    #1
    Registered Users 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 Posts: 2,150 ✭✭✭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 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