B4J Question Debugging desktop UI, B4J versus B4A

Didier99

Member
Licensed User
This is not really a question, more like a rant, so you can just skip if you are not in the mood :)

I have found that debugging UI issues is much easier on B4A than B4J because B4A executes UI calls immediately (like changing the color of a widget, or writing text into a label, or changing the property of a UI widget and reading it back) whereas B4J executes UI calls seemingly all at once when you leave the function where these calls are made, so you can't really single-step through the UI code in B4J to see what the code does like you can in B4A. I can use Sleep(0) statements to force a screen refresh, but that makes the routines resumable and complicates the overall flow, creating other issues.

I am working on a new B4J project at the moment that is fairly UI intensive (maybe a mistake on my part to implement the functionality the way I did) and I find that I spend a lot more time debugging those UI issues than I do on the functional code itself and it is frustrating. The amount of code reflects that as well, as there is much more code dealing with the UI than there is to implement the basic functionality. I hope that I am missing something and that there is a way to update the UI in real time without calling Sleep(0), at least when debugging.
 

Didier99

Member
Licensed User
Sure thing:

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Private Button2 As Button
    Private label1, label2 As Label
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
End Sub

Sub Button1_Click
    xui.MsgboxAsync("Hello World!", "B4X")
    label1.Text = "Label 1"
    label2.Text = "label 2"
End Sub

Sub Button2_Click
    label1.Text = ""
    label2.Text = ""
End Sub

and add to the form Button1, Label1, Label2 and Button2

If you put a break point on "xui.MsgboxAsync("Hello World!", "B4X")", click on Button1 and single step through the 3 lines under Button1_Click, the screen is not updated until you fall out of the function.

If you do the same thing under B4A, the screen is updated as you step through.
 
Upvote 0
Top