[fpc-pascal] pas2js: registering jQuery Mobile event callback

Michael Van Canneyt michael at freepascal.org
Thu Jul 18 06:04:45 CEST 2019

On Thu, 18 Jul 2019, Simon Ameis wrote:

> Am 17.07.2019 um 23:46 schrieb Michael Van Canneyt:
>> Several ways, but
>> TJSOBject(JQuery('#elementid'))['onhide']:=@yourfunction;
>>  should work.
> Thanks for the hint to the libjquery unit. This helps to resolve
> $('#elementid').
> However I couldn't find any information on how to access the
> non-standard events via attributes. Thus I create an external class just
> for the "on" method.

See above.

Either you declare an external class, or you typecast to
TJSObject (the generic Object from javascript) and use the 
standard 'properties' array.

There is no other way.

The web unit contains a declaration for most HTML elements.
if the events you need are standard HTML elements, the TJSHTMLElement class
or one of its descendents are all you need. if the event is a custom event,
then you need either an external class or the above.

Given that pascal is supposed to be type safe, I would always go for the
external classes approach. It has the additional advantage that the lazarus
code completion will create a handler of the correct signature for you.

with the cursor on @mymethod, invoking code completion (CTRL-SHIFT-C)
will create the method for you with the correct signature.
Saves typing, and you know your handler is correct.


More information about the fpc-pascal mailing list