binding DOM elements in DoRun is not persistent? lazarus / 76-Pas2JS ---------------------------------------------------------------------- nomorelogic · 2022-05-22 17:04 hi all I'm playing with pas2js reproducing an example found in blaise pascal magazine. Development environment is Lazarus 2.2.2 + Pas2Js 2.2.0. Follow some code from attached project: 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 procedure TMyApplication.doRun; begin  // Your code here  BindElements;  btnLogin.AddEventListener('click',@DoLoginCLick);   Terminate;end; procedure TMyApplication.BindElements;begin  Writeln('BindElements');  edtEmail:=TJSHTMLInputElement(GetHTMLElement('edtEmail'));  edtPassword:=TJSHTMLInputElement(GetHTMLElement('edtPassword'));  btnL ogin:=TJSHTMLButtonElement(GetHTMLElement('btnLogin'));end; procedure TMyApplication.doLoginClick(aEvent: TJSEvent);begin  Writeln('doLoginClick');  // BindElements;   // <- uncomment and all works!  writeln('edtEmail.Value = ', edtEmail.value);    // <- this give the error  DoServerLogin(edtEmail.Value,edtPassword.Value);end;  At runtime, if I click on LoginButton I get this error: 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 project_login.lpr:45 Uncaught TypeError: Cannot read properties of undefined (reading 'value')    at Object.doLoginClick (project_login.lpr:45:40)    at HTMLButtonElement.cb (rtl.js:249:1)  Anyway if I uncomment "// BindElements" from "procedure TMyApplication.doLoginClick(aEvent: TJSEvent)"  all works well... Where I'm wrong? thanks nomorelogic ---------------------------------------------------------------------- nomorelogic · 2022-05-24 07:47 I got the solution from Michael Van Canneyt follows the solution QuoteNormally the bind should be persistent. I use the described technique since several years meanwhile. Please check if your program code contains an Application.Free after the Application.Run. If it does, remove it. Earlier versions of Lazarus generated this statement erroneously when using the 'new web application' wizard.