As a contribution towards workarounds or hacks to get things done, I present this demo of a Global Function Hack.
The project has 2 screens. I have the function in screen 1 but I am calling it from screen 2. You will see that every time you click the button in screen 2, the function in screen 1 is executed and the result is shown in the label in screen 2.
I looked around quickly in the screen captioned scrGlobalFunctions but could not figure out how it is implemented. I may need to look again, maybe it is done in a better way.
I can tell you that it would take me a little while to understand the full implementation too! I’ve seen it work well, though!
Yours is far. more straightforward
Say what? Timers function on non-active screens?
It seems so. Even though the screen is not the active one, the
timer Fires block runs once you set the
timer enable to true.
I also found out that if you keep all timer options in the setup screen disabled then it will only run once which is what I was looking for. At first I was keeping an extra block of code in the function to turn the
timer enable option to false but then I realized I do not need it.
This gave me an ideia, what if we could update the label in screen 2 on resultHandler change event?! I tried it but with no sucess .The event is not fired when resultHandler changes inside the timer
If this was possible we wouldn’t have gone all this rounded path to get it done.
The first attempt I did was with the
when initializes or changes block.
This block only detects changes within the same screen.
Just to extend the demo of
Global Function further than just adding two variables, I created another function in the first screen. This time the function executes
Web API and saves the response to a variable.
I also created a third screen that runs this function and then waits for the variable to get updated and show the response of the
Web API located in
screen 1 in the labels of
Another enhancement in this demo is in the
timer component which now has a conditional parameter to decide which function to execute making use of one single
timer to run more than on
function as inquired by @paulovaz72
Hope this makes the demo more interesting.