Bug? Circular update problem

Informatix

Expert
Licensed User
Longtime User
This project is a typical example of circular update (a click on the listview updates the slider position, which updates the listview selection). With properly written setters, this should not be a problem. In this project, if you select an item in the listview, everything works fine. But if you try to move the slider or change the value many times in the ComboBox, there's an obvious problem that I was unable to solve.
 

Attachments

  • CircularBug.zip
    2.1 KB · Views: 197

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is not a bug. Most of the UI events are being sent to the message queue and then processed. This can cause such issues.

One possible workaround:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form

   Private ListView1 As ListView
   Private Slider1 As Slider
   Private ComboBox1 As ComboBox
   Private LastEvent As Long
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   'Loads the form layout
   MainForm = Form1
   MainForm.RootPane.LoadLayout("main")

   'Fills the ListView and the ComboBox with numbers
   For i = 0 To 99
       ListView1.Items.Add(i)
       ComboBox1.Items.Add(i)
   Next

   'Shows the form
   MainForm.Show
End Sub

Sub   ComboBox1_SelectedIndexChanged(Index As Int, Value As Object)
   If DateTime.Now < LastEvent + 10 Then Return
   LastEvent = DateTime.Now
   If ListView1.SelectedIndex <> Index Then
       ListView1.SelectedIndex = Index
   End If
   If Slider1.Value <> Index Then
       Slider1.Value = Index
   End If
End Sub

Sub ListView1_SelectedIndexChanged(Index As Int)
   If DateTime.Now < LastEvent + 10 Then Return
   LastEvent = DateTime.Now
   If ComboBox1.SelectedIndex <> Index Then
       ComboBox1.SelectedIndex = Index
   End If
   If Slider1.Value <> Index Then
       Slider1.Value = Index
   End If
End Sub

Sub Slider1_ValueChange (Value As Double)
   If DateTime.Now < LastEvent + 10 Then Return
   LastEvent = DateTime.Now
   Dim IntValue As Int = Value
   If ComboBox1.SelectedIndex <> IntValue Then
       ComboBox1.SelectedIndex = IntValue
   End If
   If ListView1.SelectedIndex <> IntValue Then
       ListView1.SelectedIndex = IntValue
   End If
End Sub
 

Informatix

Expert
Licensed User
Longtime User
This is not a bug. Most of the UI events are being sent to the message queue and then processed. This can cause such issues.

One possible workaround:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form

   Private ListView1 As ListView
   Private Slider1 As Slider
   Private ComboBox1 As ComboBox
   Private LastEvent As Long
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   'Loads the form layout
   MainForm = Form1
   MainForm.RootPane.LoadLayout("main")

   'Fills the ListView and the ComboBox with numbers
   For i = 0 To 99
       ListView1.Items.Add(i)
       ComboBox1.Items.Add(i)
   Next

   'Shows the form
   MainForm.Show
End Sub

Sub   ComboBox1_SelectedIndexChanged(Index As Int, Value As Object)
   If DateTime.Now < LastEvent + 10 Then Return
   LastEvent = DateTime.Now
   If ListView1.SelectedIndex <> Index Then
       ListView1.SelectedIndex = Index
   End If
   If Slider1.Value <> Index Then
       Slider1.Value = Index
   End If
End Sub

Sub ListView1_SelectedIndexChanged(Index As Int)
   If DateTime.Now < LastEvent + 10 Then Return
   LastEvent = DateTime.Now
   If ComboBox1.SelectedIndex <> Index Then
       ComboBox1.SelectedIndex = Index
   End If
   If Slider1.Value <> Index Then
       Slider1.Value = Index
   End If
End Sub

Sub Slider1_ValueChange (Value As Double)
   If DateTime.Now < LastEvent + 10 Then Return
   LastEvent = DateTime.Now
   Dim IntValue As Int = Value
   If ComboBox1.SelectedIndex <> IntValue Then
       ComboBox1.SelectedIndex = IntValue
   End If
   If ListView1.SelectedIndex <> IntValue Then
       ListView1.SelectedIndex = IntValue
   End If
End Sub
Thank you. It works fine in my app.
 
Top