Superclass has already implemented the event

Hi All,

I’m converting my project in real basic (2011 R2) to Xojo (2015 R2.2) but I’m getting these errors called “Superclass has already implemented the event” which makes no sense. Have any one come across a situation like this? I searched this forum but I could not find a similar incident with an acceptable answer.

I’m attaching a screenshot of the errors I’m getting. There are 45 errors and they are all similar. Unfortunately I cannot copy the log form the error window.

Log 1
Log 2

  • I did look in the deprecations over the years I couldn’t find anything solid

Is there a way to resolve this without hacking? (an update for fix perhaps)

Any help in this regards in much appreciated.


Normally this error message means exactly what it says.

There is an Object XYZ (replace XYZ with any object named in the error message)… XYZ is a subclass of something else.

In the subclass definition an EVENT was defined (such as OPEN)… and then the INSTANCE of the subclass also tried to implement the SAME event. If the subclass already implemented (ie. overrode the superclass), then the subclass cannot implement it as well… UNLESS the subclass has a new event with the same name defined… Sounds confusing I know… but I can’t think of a better way to describe it… Inheritance can be confusing if not done properly. [but works great once you understand it]

Technically this should never have worked in ANY version of RealBasic/RealStudio/Xojo, so if it did, the error existing in the previous version, not in the current one.

So in your example… CONTEXTMENUMOVIESETTINGS is a subclass derived from CONTEXTUALMENU

You have a class called ContextualMenu and it implements the Open and Action events.

Then there are several instances placed on a window or container control that also implement those events. You can’t implement an event multiple places, hence the error. This situation can arise multiple ways.

A probable fix is to go to the ContextualMenu class and add new ‘Event Definitions’ for Open and Action (these are then what the instances will be implementing). In the class call those new events at the appropriate place.

[code]Class ContextualMenu inherits ??

Event Definition Sub Open() //new event definitions
Event Definition Sub Action()

Sub Open() //classes implemented event
//yada yada
RaiseEvent Open //call the new event used by subclasses/instances
End Sub

Sub Action()
RaiseEvent Action()
End Sub

End Class[/code]

I see now that ContextualMenu was a built in class but has been removed. So I think your error is more that there is no super class. If so you may be able to make your own replacement, but I can’t find documentation of what it was so I don’t know.

Hi All,

Thank you very much for your support. I think Will Shank came close. This is happening because Xojo is not using this class anymore. I found the exact issue I’m having here.

My issue is this has been used all over my old RB project. I’m wondering if there is a more easier solution than the one described in above link. May be another class I can use instead of this one? Or import the old class from RB?

Or a solution using “RectControl.ConstructContextualMenu” ?

I found an example project in Xojo under desktop-> Menus called “ConstructContentualMenu” which works. This is adding the event handler to the window.

In my case it happens because it is directly trying to inherit form the class “ContextualMenu”. To get a better idea please see this screenshot here

There are many instances and I’m trying to implement the solution given in the above link and the example. If this works I will have to change bunch of places to get this working. If there are any other suggestions please share.

Thanks again for your help

You will have to go with RectControl.ConstructContextualMenu. The ContextualMenu class has been deprecated around ten years ago and has then been removed in 2009 if I recall correctly.

You can easily replicate this controls interface and behavior. I found docs from 2006 and it’s just a Control subclass with 1 new event, 4 methods and a property.

I left that property out though. The doc describes it as…
UseMacCMM - Boolean - If True, the Help item is displayed. If False, the Help item is omitted. This has no effect on Windows or Linux.
If you’re using this then extra code is needed to add and remove the help item before and after showing the menu, but I don’t know what it should look like or what help it’s supposed to trigger. If you’re not using it then just leave it out.

So if you build this class in your project and don’t use UseMacCMM I think it should just start working. I think :slight_smile:

[code]Class ContextualMenu Inherits Control

//=============== new Event Definitions
Event Open()

Event Action(Item As String)

//============== implemented Open event
Sub Open()
theMenu = new MenuItem
RaiseEvent Open
End Sub

//============== methods
Sub AddRow(Item As String)
theMenu.Append(new MenuItem(Item))
End Sub

Sub AddSeperator()
theMenu.Append(new MenuItem(MenuItem.TextSeparator))
End Sub

Sub DeleteAllRows()
for i As integer = theMenu.Count - 1 downto 0
End Sub

Sub Open()
dim m As MenuItem = theMenu.PopUp(System.MouseX, System.MouseY)
if m <> nil then RaiseEvent Action(m.Text)
End Sub

//============= properties
Private theMenu As MenuItem

//UseMacCMM As Boolean //?

End Class[/code]

I think Will Shank has the answer. Thank you very much for that. I think you saved me lot of time :slight_smile:

But I have one question. Why do you have two “Sub Open()” methods?

The errors relating to this class went away but there are plant other piping out in the project. This is an old project I’m trying to convert to Xojo. Therefore until I solve all of them I cannot confirm this works 100%. But as if now it’s looking good.

Again thanks every body for helping me :slight_smile:

Those aren’t Open methods, they’re actually both sides of events. When you create a subclass of Control it comes with 2 events: Close and Open. I implemented the Open event (B) to create the MenuItem property, but that uses up the event and then isn’t available to instances on a Window. So a new Open event (A) is defined and called from B to chain the ‘event’ across.

To add B you choose “Event Handler…” and then select Open
To add A you choose “Event Definition” and then name it

[code] //=============== new Event Definitions
Event Open() //A

//============== implemented Open event
Sub Open() //B
theMenu = new MenuItem
RaiseEvent Open
End Sub[/code]

So, that’s why I made it that way but I realize an easier way: delete both A and B and just add this method

Sub Constructor() theMenu = new MenuItem End Sub

:slight_smile: looking at the class now I see the 3rd Open

Sub Open() dim m As MenuItem = theMenu.PopUp(System.MouseX, System.MouseY) if m <> nil then RaiseEvent Action(m.Text) End Sub

This is a method, it’s what you call to show the menu. And even though there’s no conflict between methods and events I feel funny when they share names.

Thanks a lot for that inspiration, Will! I always thought replacing a view like from a Canvas would be the only way to create a Mac OS X custom control but now it looks like using a RectControl does work and does not need any view tampering (except for adding it to its superview of course). Should make the handling of custom controls much easier.

Actually it’s a subclass of Control, not RectControl. A Control subclass gets Open and Close events that fire with the Window opening and closing. You can also add regular Object subclasses to a Window, like Timer. These all get added to the bottom bar in the Windows Layout while RectControls live in window space.

Inheriting from Canvas really is the best way to embed a custom view right now. Don’t inherit directly from RectControl.

Ok, thanks, Joe. I find replacing the subview (or adding another subview) more difficult to handle and as it turned out RectControl does have a NIL handle during it’s open event so I could just attach a subview to the window the control resides in.
But then I had to see RectControl always gives an NIL parent even if enclosed in another control on open, so that seems to be the main problem with it as a base class.
I think I always forgot to file a feature request for a usercontrol on desktop like on iOS, especially because I remember having read you don’t recommend tweaking the view of a control. And while Canvas comes with a multitude of events preinstalled, I found myself creating duplicates of them like “ExtendedMouseclick” where I forward some more information to the event. So I’d really love to have a clean base class for custom controls if possible. I’ll file a request.