The code below returns an IllegalCastException on Next:
For Each c As Control In Self.Controls
  Select c IsA TextField
// havin Case or not change nothing to the matter
  End Select
Next
In the mean time, I will use If Then block…
The code below returns an IllegalCastException on Next:
For Each c As Control In Self.Controls
  Select c IsA TextField
// havin Case or not change nothing to the matter
  End Select
Next
In the mean time, I will use If Then block…
I commented my Select Case Block (far larger than above), added one if line and get the same error. Doh 
Used line:
If c IsA DesktopListBox Then Beep
Here comes the sun.
I commented everything inside the For Next block, then remove the commented code, the error is there too.
Maybe a cache cleaning + a shutdown-reboot will repair that ?
The debugger should stop and show you exactly which line it is causing the IllegalCastException.
Tip: Make sure you don’t cross the beams between Desktop-Prefixed-Controls and the classic names, because the difference in their super classes could be the cause of your IllegalCast.
Hi Tim,
After Clearing the cache, shut off, wait minutes, boot, add a 6 lines header, copy/paste the code from the LR, I still get the IllegalCastException in the Next line.
Screenshot:


At last, you are right, a click in the debug line shows:
Not everything in Self.Controls is a Control. DesktopContainerControl for example isn’t a control. If you are using DesktopContainerControl in your window you need to use the following:
For Each c As Object In Self.Controls
  if c IsA DesktopUIControl then
      // Deal with Controls
  elseif c IsA DesktopContainerControl
      // Deal with DesktopContainerControl
  End if
Next
Almost certainly, if you have a mixture of API1 and API2 controls. When I was converting to API2, I had to temporarily double the code inside an IMSplitter method or two, for exactly this reason. Once the conversion was complete the new code became that to keep and the original was removed. This was because one had to iterate over old and new controls.
This exception is showing that the next control in the iterable is unable to be cast to the type Control (type for c) because Control is API 1 and DesktopGroupBox is API 2.
You’ll have to adapt your code to avoid problems when mixing the frameworks. The simplest way for now would be to change the for each to Variant.
To be clear:
a. this is a project created with Xojo 2024r3.
b. Everything is Desktopxxx.
c. I tested everything I am talking about.
d. The code from the LR crash too with only a TabPanel in the window, code in the MouseDown.
Share a project where the window have:
DesktopTextField,
DesktopButton,
DesktopGroupBox,
DesktopTabPanel
and you can scan the Control List using Xojo 2024r3 and API2 (or API3 if you can).
No theory here, only facts.
PS: I cleared the Cache and shotdown / reboot, fire only Xojo, no internet, no other running application.
Sequoia .01 / MacBook Pro m1.
Then use DesktopUIControl not Control
Edit: Actually, I don’t think we can use DesktopControl because of DesktopContainer. I believe we are actually meant to use Variant.
Don’t forget that you’ll also need to look for the full DesktopTextField with your isa statements.
Yes, you have to check for (and handle) DesktopControl, and DesktopContainer. That is what I changed IMSplitter to do, during my transition.
Only running in the IDE and API2 here:

What I just said, is still the case.
If you were to add a DesktopContainer(Control) to the DesktopWindow, then using the type DesktopControl in the for each would eventually throw an IllegalCastException.
Since this thread got a little difficult to follow, here’s what you’re looking for:
// Iterate every control
for each vCtl as Variant in self.Controls
  // Select case, looking for a true comparison
  select case true
  case vCtl isa DesktopTextField
    DesktopTextField(vCtl).Text = "Text Field"
    
  case vCtl isa DesktopButton
    DesktopButton(vCtl).Caption = "PushButton"
    
  end select
  
next vCtl
Yes, that works fine.
The documentation says: Window — Xojo documentation
Should you not be looking here?
https://documentation.xojo.com/api/user_interface/desktop/desktopwindow.html#desktopwindow-controls
Maybe you copied the wrong code?
From: DesktopWindow.Controls the code is
For Each c As Object In Self.Controls
  If c IsA DesktopTextField Then
    DesktopTextField(c).Enabled = False
  End If
Next
see c as Object and not c as Control.
My guess is that you looked at the deprecated Window.Controls
Edit: I see that you answered while I was typing this message.
If you are using DesktopWindow you should not follow the LR for Window.
That is the old documentation for Window, not the new API2 DesktopWindow.