Can anyone give me an example of event handling in Webassembly (eg button click).
I have tried the following:
method HelloWorld;
begin
writeLn('HelloWorld');
var el := WebAssembly.GetElementById('helloWorld');
if el = nil then begin
writeLn('Element by ID test is null!');
exit;
end;
var t2 := WebAssembly.CreateTextNode('Hello from Elements WebAssembly!');
el.appendChild(t2);
WebAssembly.GetElementById('btn1').onclick := new WebAssemblyDelegate(a -> DoButtonClick(a));
end;
method DoButtonClick(sender: dynamic);
begin
writeLn('ID of clicked button = ' + sender.getAttribute('id'));
end;
end;
My html file includes a button element with id=âbtn1â
But this creates the following exception from sender.getAttribute(âidâ)
!> Exception of type TypeError on thread 0001
!> Message: TypeError: Cannot read property âapplyâ of undefined