|
<< Click to Display Table of Contents >> Navigation: Forum > How to change the value on the fly? |
05-18-2023, 06:14 AM:
Hello,
Is there a way? If when done use the command JavaScript (may be calling a JS function or changing a variable in JS) with Dephi and let that command run. without having to wait for the end of that Event
I would like to expand on the above message as follows. :
Because of that from which I tested for example
Inside the event of IWBTN1AsyncClick
I have a loop, or a Delphi subcommand loop, to do something. And in the meantime I want to change JS variable values or call JS functions with Delphi.
Let me give you a simple example:
Code:
for I := 0 to 100 do
begin
for J:= 0 to 10000000 do
//--DO something
begin
end;
//-- Call JS function to update progress value :
WebApplication.CallBackResponse.AddJavaScriptToExecute('UpdateProgress("Processing..", "' + I.tostring +'");');
// WebApplication.ExecuteJS('UpdateProgress("Processing..", "' + I.tostring +'");');
// AddToInitProc('UpdateProgress("Processing..", "' + I.tostring +'");');
// IWBTN1.AddJavaScriptToExecute('UpdateProgress("Processing..", "' + I.tostring +'");');
//-- or Maybe Update JS value :
WebApplication.CallBackResponse.AddJavaScriptToExecute('MyPlVar = ' + I.tostring + ';');
// WebApplication.ExecuteJS('MyPlVar = ' + I.tostring + ';');
// AddToInitProc('MyPlVar = ' + I.tostring + ';');
end;
Or to give a clearer example, let's say I have a JS Plugins to display the Cricle Pregress Loader and show the value as a percentage. while some operations are in progress This will prevent the user from clicking anywhere and knowing that the process is in progress.
But the result is not what I want.
That is, the value that I want to change or the function that I want to call. It wasn't immediately called. But only to be called at the end of the event of IWBTN1 being clicked.
Please suggest me what should I do or use.
Thank you
05-18-2023, 11:35 PM:
There is a way of obtaining this result but the process can't be done in a blocking request (i.e. a request that won't return until the process is finished). In this regard, even an async request is a blocking request from the server point of view.
You need to start a background thread on the server side that will handle the long process. The thread should update a progress counter that is read by the TIWMonitor that can update the page. There is an example of such thing here:
https://github.com/Atozed/IntraWeb/tree/...IWMonitor2
I'll see if I write a better example on how to deal with long processes using the IWMonitor class
05-19-2023, 04:39 AM:
(05-18-2023, 11:35 PM)Alexandre Machado Wrote: [ -> ]There is a way of obtaining this result but the process can't be done in a blocking request (i.e. a request that won't return until the process is finished). In this regard, even an async request is a blocking request from the server point of view.
You need to start a background thread on the server side that will handle the long process. The thread should update a progress counter that is read by the TIWMonitor that can update the page. There is an example of such thing here:
https://github.com/Atozed/IntraWeb/tree/...IWMonitor2
I'll see if I write a better example on how to deal with long processes using the IWMonitor class
Thanks Alexandre,
I have attended the sample as you suggested.
But still can't see how to apply it to my case.
I don't know if you can provide a short code example.
Or if there is an opportunity and you find it appropriate, please bring an example to apply this to my case or similar.
Initially, I would have to use LockOnAsynEvent property first.
Thank you very much
05-24-2023, 08:29 AM:
Hi Baxing,
I'm working on a new example that will probably work for you. I'll see if I can finish it by tomorrow.
Also, while working on it I found few things that could be extended in IntraWeb core and also some components that I think would be handy for this case and similar. Possibly I'll release an update containing some stuff. Hopefully you are using the latest version...
05-24-2023, 10:06 AM:
Hi Alexandre,
That is very good news for me.
Thank you for taking the time to do this and I hope it will be helpful to others as well.