Hi,
I have a query regarding calling Delphi functions from JS. If you look at the code below:
type
TForm1 = class(TWebForm)
WebButton1: TWebButton;
WebButton2: TWebButton;
procedure WebButton1Click(Sender: TObject);
procedure WebButton2Click(Sender: TObject);
procedure Form1Create(Sender: TObject);
private
MyVar:String;
procedure ShowMyVar;
end;
implementation
{$R *.dfm}
procedure TForm1.Form1Create(Sender: TObject);
begin
MyVar:='This is MyVar!';
end;
procedure TForm1.WebButton1Click(Sender: TObject);
begin
asm let _MyVar=this.MyVar; end;
asm alert(_MyVar) end;
end;
procedure TForm1.WebButton2Click(Sender: TObject);
begin
asm let _ShowMyVar=this.ShowMyVar; end;
asm _ShowMyVar() end;
end;
procedure TForm1.ShowMyVar;
begin
ShowMessage(MyVar);
end;
end.
If we call WebButton1Click, the code works as I expect.
However, if we call WebButton2Click, the compiler says that MyVar is undefined.
If I use the debugger, I see that when we get inside the function call _ShowMyVar() , this suddenly becomes undefined and stops pointing to the class object.
Is this expected behaviour? And if so, could you direct me as to how to call Delphi functions using JS function pointers?
I have a workaround at the moment that involves creating a static object of the class object in the class itself and using that to call the functions, but this is very inelegant.
Thanks!