On the ChangeScript of the text property of a TextField I update the underlying database field.
Pressing "Do", the value on the db is read and written on the green label:
Why I'm doing this? This is just the easiest way to show the problem that I have, that is: when i execute the 'DO' button ActionPerformed event, the database is not necessarily updated. If the update is quick, I find it updated. If it's a bit slow, i find it not yet updated. To simulate this you just need to add a delay in the text Change Script:
from time import sleep
sleep(1)
system.db.runPrepQuery("UPDATE MYTAB SET TEXT = ? WHERE ID = 1", [currentValue.value]);
Now if you try the example you'll see that the read text is always one step back.
If you type "A" then press "Do", you'll see nothing (or whatever value was in the record with id=1 of the table), but now if you type "B", when you press "Do" you'll see A. And this happens consistently.
The problem is that updating the record triggers some custom logic at the database level. Despite it's executed in the update transaction, it seems like the ActionPerformed event finishes before and so 'sees' the db not yet updated; this is a problem because that logic is infact validation logic that should prevent the further action contained in the button from being executed; this problem makes the application unreliable.
This actually happens because clicking on the button triggers at the same time Text Change Script and button action: whichever finishes first determines if the application works corerctly or not
All the solutions I came up with are either too complex (non trivial synchronization code in all my textfields and buttons) or require a redesign of the UI like forcing the user to press some type of confirmation button before of clicking the "Do" button.
Since either of these two solutions sound sub-optimal to me (the UI has been designed to minimize the number of clicks required to perform the action) I'm looking for a more 'orthodox' solution right from the source :-).
Thanks in advance
If you want to try the example, the table is just:
create table MYTAB ( ID INT PRIMARY KEY, TEXT VARCHAR(32))
And you'll need a record also:
insert into MYTAB (ID, TEXT) VALUES (1, '---')