Scooter Posted December 22, 2024 Posted December 22, 2024 Good day - I've run out of ideas and was hoping that someone can shed some light on my issue. I'm working on a web app, and when the user clicks a button I'd like to show the user that something is happening in the backend by changing the caption of a UniLabel from 'Good' to 'Restarting'. I perform some tasks on the server that run for about 5 seconds, so I want the user to know that something is actually happening, and that the web page has not stopped responding. In the code below, the caption 'Restarting' is never seen, even though the 'RestartCyberspace' and 'RefreshWebSites' tasks take anywhere from 5 to 10 seconds to complete. procedure TMainForm.btn_RestartServerClick(Sender: TObject); begin lbl_CyberspaceStatus.Caption := 'Restarting'; UniServerModule.RestartCyberspace; RefreshWebSites; lbl_CyberspaceStatus.Caption := 'Good'; end; I'm using UniGui Professional ver 1.95.0.1577 Quote
Sherzod Posted December 22, 2024 Posted December 22, 2024 Hello @Scooter This approach may help you: Quote
Scooter Posted December 22, 2024 Author Posted December 22, 2024 Hi Sherzod, Thank you for the fast response! I'm looking at the post right now. Quote
Scooter Posted December 23, 2024 Author Posted December 23, 2024 Hi Sherzod, Thanks once again for your assistance. In the event anyone else ends up here looking for a similar solution, this is how I ended up doing it: 1. I created a JS listener on the button that the user presses to restart the server. The JS listener is listening for the 'click' event, and when that event is received, the UniLabel object text gets set. In this example, the UniLabel is called 'lbl_CyberspaceStatus'. 2. At the end of the long running task, the UniLabel text is set to the correct status. In this simple example, the status is set to 'Good'. The end result is that as soon as the user clicks the button, the UniLabel text is set; and then once the long running task ends, the UniLabel text gets set again. Works perfect, and I think provides good feedback to the user. procedure TMainForm.UniFormCreate(Sender: TObject); begin btn_RestartServer.JSInterface.JSAddListener('click', 'function(){MainForm.lbl_CyberspaceStatus.setText("Restarting")}'); end; procedure TMainForm.btn_RestartServerClick(Sender: TObject); begin ... long running tasks ... lbl_CyberspaceStatus.JSInterface.JSCall('setText', ['Good']); end; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.