Jump to content

Recommended Posts

Posted

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

Posted

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;

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...