I attached a small program to show the problem.
Start the program
Click the left button: a screen with buttons
FrameLaadFout.zip (2.5 MB)
appears
Click the right button: the system crashes on a system error (string search)
Start the program again
Click the right button: an empty screen appears
Click the left button: a screen with buttons appear
Click the right button: crash
it is caused by the fact I added a Delphi eventhandler to the button.
Is this a WebCore bug? How else should I add an eventhandler to this button?
Best
Peter
The problem is in your code.
You assign the event handler to all buttons on the form, i.e. also the top 2 buttons. These buttons do not have the ‘actie’ attribute, hence
Sender.targetElement.getAttribute('actie')
is null and ToInteger can’t be performed on a null.
I did something like:
function TFInvoerscherm.ButtonClickHandler(Sender: TJSEvent): Boolean;
var
S : String;
attr: string;
begin
attr := Sender.targetElement.getAttribute('actie');
console.log(Sender, Sender.targetElement, attr);
asm
if (attr == null)
return;
end;
case attr.ToInteger of
-1 : S := '-1' ;
0 : S := '0';
1 : S := '1' ;
end;
end;
to workaround your bug
Wow! What a fast reaction! Very grateful!
I added the line if MyButtons[I].hasOwnProperty('actie') then
and everything works!
The license fee is worth the full money!
Thanks again.
Peter
Could I have seen this line was giving the problem? Cause I tried debugging, but it stopped in the system unit, not on the line within the click handler. If I would have known (or guessed) that was where the error was, I could have saved you and me a lot time …
If there is an error
TypeError: Cannot read properties of null ()
that typically means you are dealing with a null object.
The error further says
at Object.TryStrToInt$2 (http://localhost:8000/FrameLaadFout/FrameLaadFout.js:4301:20) at Object.StrToInt
so, that made it point to me to your .ToInteger function use of a null object.