Trouble with subclassing a control subclass

I subclassed a Canvas control and named it MyCanvas. In this subclass I added mouse down/up events. In the mouse up event I call a method I added named DoClick. This works fine when I put an instance of MyCanvas in the Window. Now, I subclass the MyCanvas as CustomMyCanvas. I add a method named DoClick to this CustomMyCanvas subclass. I put an instance of the CustomMyCanvas on the Window. When I click on the CustomMyCanvas, the DoClick method for it’s Super, MyCanvas, is executed. Not the method for the CustomMyCanvas subclass. There is a simple demo of this at: http://allmytrash.com/XOJO/TestSubclass.zip. What am I doing wrong??

Thanks,
Louis

Don’t have 2 methods named “DoClick” CustomMyCanvas already inherits DoClick from its Parent. If you want another version, name it something else.

I thought subclass methods overloaded superclass methods if they were the same name. i.e. subclass methods were used in place of the superclass methods. Maybe this doesn’t work when subclassing built in Controls

It’s called overriding. Overloading is having a method with the same name but different parameters in the same class.

Your MyCanvas.DoClick method is private, so it can’t be overridden. Make it protected or public, so the subclass MyCustomCanvas can override it.

Thanks Eli. I thought it might be something simple. I just didn’t think about the ‘private’ scope. Thanks for the overriding terminology.

Louis

Re: Eli and the term “overriding” vs overloading:

I just ran across this on page 141 of the XOJO users guide - Fundamentals under the topic of Polymorphism.

“First, create a new class called Animal. Add to it a Speak method
that returns a String.
Now create a subclass of Animal, called Cat. Add to it a Speak
method that returns a String. This means you are overloading the
unimplemented Speak method on Animal.”

So it seems the folks at XOJO consider a method in a subclass taking precedence over a superclass method is called overloading.

That should be considered a careless mistake in the documentation. Overriding is the correct term.

That should be pointed out as the term is incorrectly used in that case

Indeed it is. Surprising no one has noticed until now!

I’ve just fixed it for the next release.