Using [async] {$I} directive file.

Hi,

Doing some testng using {$I}, looks like WebCore does not generar await for functions even if [async] is used. using "async;" after function/procedure definition works ok.

In the following code if I use the {$I} I get an error "await is only valid in async functions and the top level bodies of modules" at runtime.

procedure TSistemasForm.LoadGlobalesSistema;
{$IFDEF USEINCLUDE}
{$I 'Test.inc'}
{$ELSE}
[async]
procedure OnSuccessReaload(const ARespuesta : TRespuesta);
var
strJSON : string;
begin
if Assigned(ARespuesta) then
.....
end;
{$ENDIF}
begin
....
end;

The Test.inc file containts the extact same code as the {$ELSE} estatement.

Here is the generated code.

Not using {$I}
async function OnSuccessReaload(ARespuesta) {
var strJSON = "";
if (ARespuesta != null) {

Using {$I}
function OnSuccessReaload(ARespuesta) {
var strJSON = "";
if (ARespuesta != null) {

Looks like {$I} does not recognize the [async] kewords in the file.

In another test I get the following error at compile time if I add
the following code to the 'inc" file. "await only available in async procedure"

[async]
procedure OnSuccessEditaGlobal(const ARespuesta : TRespuesta);
begin
if Assigned(ARespuesta) then
begin
if Length(ARespuesta.Mensajes) > 0 then
MainForm.MsgDialog(ARespuesta.MensajesAsText,'Error')
else
begin
SysGlobal := TSysGlobal.FromJSON(ARespuesta.Response);
if Assigned(SysGlobal) then
begin
Id := SysGlobal.ID;
Estatus := SysGlobal.Estatus;
Await(ShowAgregaGlobal);
end;
end;
end;
end;

Any Hints?

Thanks in advance,

Omar Zelaya

[async] is typically declared on the method declaration in the form class definition.
If you need async functions elsewhere, try to add at the end of the procedure async; , i.e.

procedure OnSuccessReaload(const ARespuesta : TRespuesta); async;