Hi there,
Since I fully updated my code to the latest standards, I’ve been regularly getting an IllegalCastException when I return to my desktop app.
My app is an accounting application. When entering bank transactions, I frequently switch between my web browser (logged into my bank account) and my app. Most of the time, everything works correctly, but occasionally the app triggers this IllegalCastException.
In this case, I was in my browser and then clicked on a DSExtrait window. What I don’t understand is why the condition «Window(0) IsA DSJournal» evaluates to true, even though the active window is clearly not a DSJournal window.
Thanks in advance for your help.
Can you put Window(0) in a local variant variable there?
And then use the local variable?
with something like window(0), I always wonder if the order could change between calls.
Is DSJournal a subclass of DSExtrait?
1 Like
What do you mean when you say «put Window(0) in a local variant variable»?
Both DSJournal and DSExtrait are subclasses of DSWindow, but DSJournal is NOT a subclasse of DSExtrait.
What Christian meant is that between the second and the third line Window(0) may have changed.
Make a variable for Window(0) so that you have a fixed reference:
dim w as window = Window(0)
and change your code accordingly.
If you put it in a local variable, you can inspect it in the debugger.
And using variant makes that you don’t need to do explicit casts.
Like this:
var w as variant = window(0)
if (gActDoc.allows_create and w isA DSJournal ) then
var d as DSJournal = w
activated = d.grid.NbRowsSelected > 1
end if
which I think makes it more readable.
1 Like
Thanks for your answers. Indeed, this approach seems safer. I’m going to do this and see whether the issue still occurs.