Error with extends

If I create the following functions:

bla(extends sender as DesktopPopupMenu, a as variant)
bla(extends sender as DesktopComboBox, a as variant)

and then in the code

ComboBox1.bla("abcdef")

in the code, I get:

image

I see this as a bug, it is quite clear which function is meant. Or am I missing something here?
Oh well, of course I’m aware that popupmenu is a super of combobox, but that shouldn’t lead to this error, should it?

Have you tried changing ‘a’ to string as it might actually be complaining about that.

It seems to be working fine. I’ve tested it with this method, as a Global Module Function:

Public Sub Bla(Extends sender As DesktopPopupMenu, a As Variant)
  If sender <> Nil Then
    System.DebugLog(sender.Name)
  End If
End Sub

Yes, if you ONLY use the extension on the super, popupmenu it works, but if you add the second,m it doesn’t

I’ve added both methods and it still works with both controls, could you please paste some code or a sample project?

One of your methods is named Bla1.

2 Likes

Ah, right. I’m seeing the error now, thanks.

1 Like

https://nözl.de/pupc6

The error is correct. When you call Bla on a ComboBox, either version could be correct.

If you have just one method, you can check if the control is a ComboBox or a PopupMenu using IsA.

Public Sub Bla(Extends sender As DesktopPopupMenu, a As Variant)
  Select Case sender
  Case IsA DesktopComboBox
    Break
  Case IsA DesktopPopupMenu
    Break
  End Select
End Sub
2 Likes

Yes, of course. But that ist a workaround. I could not see, why that could not be handled from by Xojo itself.

Then why doesn’t the compiler complain about this?

bla(extends sender as DesktopPopupMenu, a as string)
bla(extends sender as DesktopComboBox, a as string)

That’s a good question. I know variants mess things up, but that’s not the behavior I expected.

Ok, but why does it work, when using:

bla(extends sender as DesktopPopupMenu, a as String)
bla(extends sender as DesktopComboBox, a as String)

Here, too, both versions can be correct.

You can open a new Issue with all that info.

What happens if you put the string into a variant variable first?

I think that will work, as ist is a layer less.

it doesn’t work because desktopcombobox is a subclass of desktoppopupmenu…

2 Likes

I just got to my computer and tested it. Yep, it works. So it’s the casting to variant that confuses things.

1 Like

But it works if:

  • use a as String instead of a as Variant
  • the string is assigned to a Variant and used instead of the String directly:

change:

ComoBox1.bla("test")

to

Var test As Variant = "test"
ComboBox1.bla(test)

it looks like there is more to it than one being subclass of the other.

1 Like