Page 1 of 1

How do you override a protected method?

PostPosted: Wed Feb 13, 2008 10:05 am
by AlGonzalez
I'm trying to implement the disposable pattern on a form by overriding the base form dispose method.

Code: Select all
    var _components as IContainer?

    def dispose(disposing as bool) #is override
        if disposing and _components
            _components.dispose
        base.dispose(disposing)


I get this warning: "TestForm.Dispose(bool)" hides inherited member "System.Windows.Forms.Form.Dispose(bool)". To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

If I uncomment the 'is override', I get this error: "TestForm.Dispose(bool)": cannot change access modifiers when overriding "protected" inherited member "System.ComponentModel.Component.Dispose(bool)"

Re: How do you override a protected method?

PostPosted: Wed Feb 13, 2008 1:03 pm
by khjklujn
They aren't in Chuck's list of keywords, so this may be a soon-to-be deprecated syntax, but public, protected, and private are recognized keywords in version 0.7.2.

To override a protected method try:
def dispose(disposing as bool) is protected, override

Re: How do you override a protected method?

PostPosted: Wed Feb 13, 2008 3:11 pm
by AlGonzalez
Excellent - thank you very much.

I thought I'd tried every combination, but apparently not.

Re: How do you override a protected method?

PostPosted: Thu Feb 14, 2008 1:56 am
by Charles
It's not a soon-to-be-deprecated syntax so feel free to use it. They are pseudo keywords meaning they are recognized in this syntax, but you can otherwise use them for variable names. By the way, I call these particular ones "is names" in the docs.

And straight from the compiler source:
_validIsNames = ['fake', 'shared', 'virtual', 'nonvirtual', 'override', 'new', 'public', 'protected', 'private', 'internal', 'abstract']

Thanks for asking these questions. I've internalized a lot of Cobra so I forget to mention these things.