[Pas2js] @pointer/reference inside ASM block - missing feature

warleyalex warleyalex at yahoo.com.br
Sun Jun 10 00:51:05 CEST 2018


Michael Van Canneyt wrote
> Why do you need @ ?

//----VERSION 1 # compile but does not work
-------------------------------------------
  P1 := TPerson.new;
  P1.Name:= 'John';
  P1.Age:= 52;
  P1.Status:= true;   

function Myfunction(const aValue: String): String;
begin
  console.log(aValue);
  result := aValue;
end;

{...}
begin
  // code here
  asm
    window.Myfunction1 = Myfunction(P1.Name);  // -->Uncaught
ReferenceError: Myfunction is not defined
  end;

end;
//---------------------------------------------------------------------------------------------
The pas2js compiler does neither parse, nor check the syntax of the JS;
smart linking did omit the Myfunction1 method, and I've got  the "Uncaught
ReferenceError: Myfunction is not defined"
-----------------------------------------------------------------------------------------------

//------- VERSION 2 # working as expected 
-----------------------------------
type
  TProc = function(const aValue: String): String of object;

  var
    p: TProc;

{...}
begin
  // code here

  p := @Myfunction; // we have to add this dummy variable to smart linking
include the Myfunction method.

  asm
    window.Myfunction1 = Myfunction(P1.Name);  // -->works
    window.Myfunction2 = p(P1.Name);               // -->works!!! 
  end;

end;
//----------------------------------------------------------------------------


//------- VERSION 3 # using @prefix suggestion
-------------------------------
{...}
begin
  // code here
  asm
    window.Myfunction1 = @Myfunction(P1.Name);  // --> should work as well
  end;

end;

//----------------------------------------------------------------------------
In Version 3, pas2js compiler quickly figure out that is an Object Pascal
variable, understands the @ character and it will initialize/auto include
the Myfunction for us. :)
-----------------------------------------------------------------------------




--
Sent from: http://pas2js.38893.n8.nabble.com/


More information about the Pas2js mailing list