Questions About the sleep/delay implementation

Questions about the sleep implementation

I saw many articles on [support center] to implement the sleep/delay function.

The two methods I've found are:

both works fine!!
However, a problem arises during development.


  1. Use the WebUtils unit

uses WebUtils;

procedure Tfrm_SubDash.WebButton1Click(Sender: TObject);
begin
//delay
Await(boolean, AsyncSleep(1000));
end;


  1. Use JavaScript directly

procedure Tfrm_SubDash.WebFormCreate(Sender: TObject);
begin
asm
window.sleep = async function(msecs) { return new Promise((resolve) => setTimeout(resolve, msecs)); }
end;
end;

procedure Tfrm_SubDash.WebButton1Click(Sender: TObject);
begin
//delay
asm await sleep(1000); end;
end;

■■■ Both of the above work well.■■■

However, a problem arises during development.

*** FYI, I'm developing with Delphi 10.3.

:arrow_forward: Case 1

uses WebUtils;

As above, WebUtils; If I do

Delphi code autocompletion does not work.

For example WebButton1. If you enter , the code auto-completion window should appear, but it does not appear.

:arrow_forward: Case 2

asm end;

If I type the phrase and hit enter, [end;] is automatically created again.

ex)

asm await sleep(1000); end; (Enter)

end; <-- added automatically

I'm having trouble with the problem in 1) and 2) above.

Any workaround?

To make the code completion (that is based on the Delphi Win32 compiler) happy, put this code in asm blocks the compiler doesn't understand in a block

{$IFDEF PAS2JS}
// JavaScript code here
{$ENDIF}
1 Like

It works perfectly!

[TMS Webcore] is a great invention!
What a great solution.

Thank you very much.

2 Likes

:point_up: