Why this.edtEmail is undefined? lazarus / 76-Pas2JS ---------------------------------------------------------------------- cappe · 2022-11-07 14:55 Why with this code: {$mode objfpc} uses   browserapp, JS, Classes, SysUtils, Web, fpjson, fpjsonjs, fprpccodegen; type   { TMyApplication }   TMyApplication = class(TBrowserApplication)     edtEmail: TJSHTMLInputElement;     edtPassword : TJSHTMLInputElement;     btnLogin : TJSHTMLButtonElement;     procedure doRun; override;   private     procedure BindElements;     procedure doLoginClick(aEvent: TJSEvent);     procedure doServerLogin(const aUser, aPassword: String);   end; procedure TMyApplication.doRun; begin   BindElements;   btnLogin.AddEventListener('click',@DoLoginCLick);   Terminate; end; procedure TMyApplication.BindElements; begin   edtEmail:=TJSHTMLInputElement(GetHTMLElement('edtEmaill'));   edtPassword:=TJSHTMLInputElement(GetHTMLElement('edtPassword'));   btnLogin:=TJSHTMLButtonElement(GetHTMLElement('btnLogin')); end; procedure TMyApplication.doLoginClick(aEvent: TJSEvent); begin   window.alert(edtEmail.value);   DoServerLogin(edtEmail.value,edtPassword.value); end; procedure TMyApplication.doServerLogin(const aUser, aPassword: String); begin   window.alert('Logging in with user: '+aUser);   // to be implemented. end; Why does doLoginClick give me the following error? A seems correct. Uncaught TypeError: this.edtEmail is undefined     doLoginClick client.lpr:50     cb rtl.js:256     DoRun client.lpr:29     Run custapp.pas:206     $main client.lpr:66     run rtl.js:141 ---------------------------------------------------------------------- lainz · 2022-11-07 15:04 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 'edtEmaill' It has double L in the end ---------------------------------------------------------------------- cappe · 2022-11-07 15:09 Quote from: lainz on November 07, 2022, 04:04:21 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 'edtEmaill' It has double L in the end That's not the problem, I have attached the project, I try with pas2js 2.2.0 I can't get it to work. The strange thing is that inside the BindElements works, edtEmail works correctly, while in doLoginClick it gives me "Uncaught TypeError: this.edtEmail is undefined" ---------------------------------------------------------------------- 440bx · 2022-11-07 22:22 @cappe, your opening post would be much easier to read if you used code tags to format the code. ---------------------------------------------------------------------- PierceNg · 2022-11-08 02:53 Quote from: cappe on November 07, 2022, 04:09:44 pmThat's not the problem, I have attached the project, I try with pas2js 2.2.0 I can't get it to work. The strange thing is that inside the BindElements works, edtEmail works correctly, while in doLoginClick it gives me "Uncaught TypeError: this.edtEmail is undefined" "It works on my computer"TM with pas2js 2.2.1. The login box is displayed, the alert modal pops up, and browser console shows no relevant error. ---------------------------------------------------------------------- yus · 2022-11-09 02:17 Remove Application.Free; 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 ...var  Application : TMyApplication; begin  Application:=TMyApplication.Create(nil);  Application.Initialize;  Application.Run;//  Application.Free;end.