Stack overflow error with SelectedPanelIndex?

Hello all,
Basically I have a tabbed panel with 2 panels and a variable that controls which set of controls is shown by the tabs. If the user tries to move to an unauthorized tab I want that to be pretty much denied and reversed. The below code is pretty simple, am I misunderstanding this or is this a bug? Thanks!

Sub PanelChanged() Handles PanelChanged 
  If(panelMode=0) Then
    Me.SelectedPanelIndex=0
  Else
    Me.SelectedPanelIndex=1
  End
End Sub

In PanelChanged the panel has already been changed. So the stack overflow is no wonder. I would recommend a canvas based tab panel so that you can prohibit the panel change on your own.

I know the panel has already been changed but wouldn’t this just change it back? Or does changing the panel via “SelectedPanelIndex” also trigger the panelchanged event making an infinite loop?

As the result of your code is a stack overflow the answer is “yes”.

You need something similar to “cancelclose” for windows. And this is only doable with a canvas.

1 Like

Time for one of my Quick&Dirty “fixes” :slight_smile:

Sub PanelChanged() Handles PanelChanged 
  If(panelMode=0) And Me.SelectedPanelIndex<>0 Then
    Me.SelectedPanelIndex=0
  ElseIf Me.SelectedPanelIndex<>1 Then
    Me.SelectedPanelIndex=1
  End
End Sub

Are you working on Mac or Windows?
Do you have an example? I can’t reproduce the problem on a mac, maybe I’m missing something.

Unfortunately seems like it never runs the code :frowning:
I also tried:

Sub PanelChanged() Handles PanelChanged 
If(Me.SelectedPanelIndex<>panelMode) Then
  Me.SelectedPanelIndex=panelMode
End
End Sub

but same thing, just kind of ignores it

Linux, When you say example do you mean like a project file?

Yes, small Xojo binary project. You can zip it and upload to the forum.

On two of the three Desktops, that works. On the third it doesn’t. Can’t remember which is which just now, not at my desk, will look in my app later and post again.

On the third desktop I do something different to make it work.

1 Like

OK turns out it is Linux that has the issue. So in my PanelChanged event I have, inter alia, this code:

if  (me.SelectedPanelIndex=currentPanel)  then Return

#if  (TargetLinux=False)  then
  me.SelectedPanelIndex = currentPanel                               // Not Linux, just set the panel back to what it was
#EndIf

#if  (TargetLinux=True)  then                                        // Linux, have to wait before reverting panel
  Timer.CallLater (1, WeakAddressOf setPanelIndex)
#EndIf

.
And the setPanelIndex method is merely:

// Only used under Linux to reset the panel. 

#if  (TargetLinux=True)  then
  PrefsTab.SelectedPanelIndex = currentPanel
#EndIf

This works for me.

1 Like