Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2019-08

is it a bug fro pas2js?

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Pedro Pablo Oviedo Vera

Hello, I have a problem:
I writing an event handler for invalid input from a html form element in order to get a validation on real time:

FFormulario1            :=
TJSHTMLFormElement(document.getElementById('informacion1'));
FFormulario1.oninvalid  ;

before I defined

function Form2Validacion(aEvent: TJSEventhandler): Boolean;
begin
  window.alert('Hay un campo con valores incorrectos!!!');
end;

knowing in web.pas say:
TJSHTMLFormElement = class external name 'HTMLFormElement' (TJSHTMLElement)

 TJSHTMLElement = class external name 'HTMLELement' (TJSElement)
 public
 oninvalid : TJSEventhandler;
 ...

but Lazarus in compile time shut me:
project1.lpr(262,28) Error: Incompatible type arg no. 1: Got "TEventListenerEvent", expected "TJSEventHandler"

if I change to:
function Form2Validacion(aEvent: TEventListenerEvent): Boolean;

and then Lazarus compiles Ok!!!

but my browser claim to me with all justice:
TypeError: $mod.FFormulario1 is null!!!!

it will be an Error???

Thanks

pp

MSc. Ing. Pedro Pablo Oviedo Vera Dirección Técnica y Desarrollo Empresa de Proyectos e Ingeniería del Ministerio de la Agricultura.ENPA. Boyeros y Conill, Piso 10 Edif MINAG Telef. 884 7197 SIP:23000116 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20190816/00d3e7f2/attachment.html>

Reply by email

Mattias Gaertner
to Pedro Pablo Oviedo Vera: Hello, I have a problem: I writing an event handler for invalid input from a html form…
Show quoted text 22 lines
Hello, I have a problem: I writing an event handler for invalid input from a html form element in order to get a validation on real time: FFormulario1 := TJSHTMLFormElement(document.getElementById('informacion1')); FFormulario1.oninvalid ; before I defined function Form2Validacion(aEvent: TJSEventhandler): Boolean; begin window.alert('Hay un campo con valores incorrectos!!!'); end; knowing in web.pas say: TJSHTMLFormElement = class external name 'HTMLFormElement' (TJSHTMLElement) TJSHTMLElement = class external name 'HTMLELement' (TJSElement) public oninvalid : TJSEventhandler;
TJSEventhandler is defined as
  TJSEventHandler = reference to function(Event: TEventListenerEvent): boolean;
Show quoted text 5 lines
... but Lazarus in compile time shut me: project1.lpr(262,28) Error: Incompatible type arg no. 1: Got "TEventListenerEvent", expected "TJSEventHandler"

Correct.

if I change to: function Form2Validacion(aEvent: TEventListenerEvent): Boolean; and then Lazarus compiles Ok!!!

Yes.

but my browser claim to me with all justice: TypeError: $mod.FFormulario1 is null!!!!

That probably means
document.getElementById('informacion1')
returned nil.

Check if FFormulario1 is nil and if "informacion1" is correct. Case sensitive.

Mattias

Reply by email

Michael Van Canneyt
to warleyalex: I think the correct TJSEventHandler type definition is: TJSEventHandler = reference to…
warleyalex wrote
I think the correct TJSEventHandler type definition is: TJSEventHandler = reference to function(event: TJSEvent): Boolean;

You are right.

And this is in fact the TJSRawEventHandler prototype (barring the boolean result). The reason was in the confusing documentation about javascript event handlers.

The best option is probably to redefine TEventListenerEvent = TJSEvent. That will make both eventhandler types identical, and should remain backwards compatible.

Michael.

Reply by email