Javascript to pas lazarus / 76-Pas2JS ---------------------------------------------------------------------- ramersonw · 2022-03-07 17:54 Hi, Hi, I'm trying to use a lib in my pas2js project, but I'm not able to make it work. I'm triyng to use the snippet below: Code: Javascript  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const myPromisse = MyPromisseInit(); myPromisse.then((data) => {  const temp = new data.SomeConstructor();})  My pascal code is as follows: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; {$mode objfpc}{$modeswitch externalclass} uses  JS; type  TData = class external name 'Object' (TJSObject)  public    constructor SomeConstructor();  end;   function MyPromisseInit(): TJSPromise external name 'MyPromisseInit';  var  test: TJSPromise;begin  test := MyPromisseInit();  test._then(function (data: JSValue): JSValue  var    _data: TData absolute data;    res: JSValue;  begin    res := _data.SomeConstructor();  end);end.  But it did not work. Compile says project1.lpr(27,18) Error: External class instance cannot access static constructor SomeConstructor What I have to change to make it work? Edited the pascal snippet with complete code. ---------------------------------------------------------------------- MarkMLl · 2022-03-07 18:19 Quote from: ramersonw on March 07, 2022, 06:54:43 pmWhat I have to change to make it work? Everything. You can't nest blocks like that, and in particular you have to declare variables (var declaration) outside the begin/end block that will reference them. Don't trust the compiler error messages until you've got the layout right. MarkMLl ---------------------------------------------------------------------- marcov · 2022-03-07 21:10 Actually that is Delphi anonymous methods syntax. ---------------------------------------------------------------------- ramersonw · 2022-03-07 23:14 Yes. It's an anonymous function and It Works with pas2js transpiler. ---------------------------------------------------------------------- MarkMLl · 2022-03-08 08:11 In that case I'd like to apologise for being misleading. MarkMLl