DesktopControl problem with new Xojo 2022 Release 3

I have a loop in the ‘Activated’-Event inside the superclass of the Mainwindow of my Desktop-app:

For Each c As DesktopControl In Self.Controls
  Select Case c.Name
  Case Else
    Continue
  End Select
Next

On the mainwindow there are four controls: DesktopContainer, DesktopLabel, DesktopSegmentedButton and a Thread.

This code works fine in Xojo Version 2022 Release 2, but crashes in Version Release 3 with a IllegalCastException: WindowMain.DefaultActionContainer_ cannot be cast to DesktopControl

Why is this code failing in the new xojo version 2022 Release3 but runs fine in Release 2?

I am guessing there is one more control now there on the window that did not exist in Release 2, something called “DefaultActionContainer”.

And that one then does not inherit from DesktopControl.

DesktopWindow.Controls() and ControlAt() return an Object. Because you have a container on your window, you need to check its type because it cannot be cast into a DesktopControl.

Try something like this instead:

For Each co As Object In Self.Controls
  If co IsA DesktopControl Then
    Var c As DesktopControl = DesktopControl(co)
    
    Select Case c.Name
    Case Else
      Continue
    End Select
  ElseIf co IsA DesktopContainer Then
    // Do something with the container
    Break
  End If
Next
1 Like