B4J Question Why is it impossible to code MainForm.Show in a DoWhile loop?

B4JExplorer

Active Member
Licensed User
Longtime User
Hi,

I'm trying to paint a different screen, each time a button a pressed. I have the screen painting routine - mainly just some buttons on the top and a text box - inside a Do While Loop.

If I comment out the Do While Loop, then the screen paints fine. But if I put the Do While Loop back in, then there's an Unreachable statement error, that points to the MainForm.Show line.

Is it possible to relabel components and refresh the display, inside a Do While? Where should the MainForm.Show be placed, so that it doesn't cause any trouble?


The following is just pseudo-code. The actual code is too complicated, right now.


B4X:
Do While True

' Paint buttons and screen
'...
'...
    MainForm.RootPane.AddNode( btn....
    '.....
   MainForm.Show

   If b_ThisIsTrue
       Exit
  End If

Loop
'...
'...
 

Daestrum

Expert
Licensed User
Longtime User
Not sure I 100% understand what you are trying to achieve.

A UI program is event driven, it will sit there quite happily forever waiting for some user interaction, it is already effectively running in an endless loop, that's why you don't need StartMessageLoop.

Button presses generate an event, in that button event handler you can do whatever you want, load a new mainform change the layout etc, when you exit that handler, the program goes back to waiting for something else to happen.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
try a sleep(0) that the event loop continue.

it would me more easier for us if the event handling runs always parallel.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Plus, the UI kinda auto-refreshes itself each time something is changed on it, so you only call 'form.show' once before your 'do while' loop
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Not sure I 100% understand what you are trying to achieve.

A UI program is event driven, it will sit there quite happily forever waiting for some user interaction, it is already effectively running in an endless loop, that's why you don't need StartMessageLoop.

Button presses generate an event, in that button event handler you can do whatever you want, load a new mainform change the layout etc, when you exit that handler, the program goes back to waiting for something else to happen.

" it will sit there quite happily forever waiting for some user interaction"

Yes, that's right. Of course. The loop isn't necessary.

Ok, thanks Daestrum, MarkusR, and Cableguy.

Daestrum, to answer your question about what I'm trying to do. It's basically a folder navigator, but not in a grid component. When you press <ENTER> on a subfolder, the current parent folder display will have to clear out, and it will have to refresh with the contents of the subfolder.

I'll share this with the community when it's done, but it's a very different concept from Total Commander .e.g., and will probably take a while.
 
Upvote 0
Top