Creating new wasm project, wrong HTML code is generated and I get error: TypeError: program.Main is not a function
This happens because Program class has now HelloWorld method instead of Main.
So I tried to change it as I found a lot of new classes and interfaces in DOM namespace
But using HTMLCanvasElement or CanvasRenderingContext2D interface casting throws TypeError when using any property. How to change this code to work again (canvas 2d)? A lot of these DOM interfaces as empty ( CanvasRenderingContext2D.vb)!?
I tried samples e.g. RemObjects Oxygene for Island\GUI\Basic WebAssembly GUI Controls App but they also fail to compile (Delphi classes not public?).
Oops, my apologies. that’s what I get form trusting someone to submit an “improved” HTML for the template :). will fix.
What’s the error? Note that a lot of DOM code now has string types, where before it was all Dynamic and everything would compile, right or wrong. See Browser & DOM and Interop.
to be clear — is the DOM API actually missing With (and others here), or is casting the right/final solution here, Theo?
Artur: the thing is GetElements returns the loosest common base type. Think of it in Delphi for WinForms terms as FindControl(). you might bet back a button or a list view, but the type is Control — you gotta cast it to the more concrete real type you know it to be, to create art as a Button or a ListView. same applies here, for more specialized HTML element types
The casting to Dynamic is a work around for now.
The casting of an element is the right / final solution.
The following can be used in the strong typed API:
var canvas := Browser.CreateElement('canvas') as HTMLCanvasElement;
This is because Browser.CreateElement returns an Element (the ancestor of each element you can create with it)
The width and other properties are available in the HTMLCanvasElement. Not in Element. So when the result of Browser.CreateElement has been casted to HTMLCanvasElement, the properties are available.