B4J Question Wait for problems

PatrikCavina

Active Member
Licensed User
Longtime User
Hi to all,
I can't understand where is my error.
After the line ' tx.text = "a" ', 'Wait for' call event _TextChanged but when event end the program don't continue.

B4X:
Private Sub Process_Globals
    Private frm As Form
    Private tx As TextField
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    frm = Form1
    tx.Initialize("tx")
    frm.RootPane.AddNode(tx,0,0,600,200)
    frm.Show
    start
End Sub

Sub start
    tx.Text = "a"
    Wait For (tx) TextChanged (Old As String, New As String)
    Log("After Text Changed")
End Sub

Sub tx_TextChanged (Old As String, New As String)
    Log("Text Changed")
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the expected behavior. The first TextChanged event will be intercepted by the Wait For line. Further events will be intercepted by the Sub. You can call it like this:
B4X:
Sub start
    tx.Text = "a"
    Wait For tx_TextChanged (Old As String, New As String)
    Log("After Text Changed")
    tx_TextChanged (Old, New)
End Sub
 
Upvote 0

udg

Expert
Licensed User
Longtime User
The first TextChanged event will be intercepted by the Wait For line
I didn't study yet the new features (so maybe it's already explained elsewhere) but I believe this is a very important point to remark.

If I understand it correctly, Wait For "consumes" the event so there's no calling of the TextChanged sub.
From that point on, instead, the sub is called repeatedly while the user types in the edit box and that consumes the events following the first one.

Can we think of it like:
1. TextField component raises the event
2. if there's no WaitFor or other item that consumes the event, TextField component looks for a properly named sub and calls it

udg
 
Last edited:
Upvote 0

udg

Expert
Licensed User
Longtime User
Ok, I gave it a first quick reading and it sounds very nice.
I guess that you referred to "Wait For events handlers precede the regular event handlers." as a way to implicitly reply to my assumption.
Thanks
 
Upvote 0
Top