[Pas2js] Call a function from html

Gabriele Cappelletto cappellettogabriele at yahoo.it
Wed Sep 4 11:23:01 CEST 2019


I get this error when calling pas.test.Btn1Click () ;. "TypeError:
Cannot read property 'Btn1Click' of undefined".
I am attaching the .js file and the html.

I have another question. If I write a function not used in the program,
the compiler does not compile it in the .js file, is there a way to
force the compilation even if the function is not used?

Thank you

Il 04/09/19 08:24, Michael Van Canneyt ha scritto:
>
>
> On Tue, 3 Sep 2019, Gabriele Cappelletto via Pas2js wrote:
>
>> Hello
>> I would like to find a way to call a function written with pas2js from
>> html code (do not define onclick from pas2js, but call from html)
>>
>> example
>> html
>> ?<input type="button" class="form-control" id="btn3" value="direct mode"
>> onclick="Btn1Click();"/>
>
> All functions live under the top-level "pas" object, per unit.
>
> So
>
> onclick=pas.YourUnit.Yourfunction()
>
> should do it.
>
> Here YourUnit and YourFunction are of course case sensitive.
>
> If the function is in the main program, then you must write
>
> onclick=pas.program.Yourfunction()
>
> with the identifier "program" in lowercase letters.
>
> You must make sure that rtl.run() has been called when the page loads.
>
>>
>> and the Btn1Click function write it with pas2js.
>> example
>> function Btn1Click(aEvent: TJSMouseEvent): boolean;
>> begin
>> ? //?
>> end;
>>
>> How can I do?
>
> Just write your function, and refer to it in the above manner.
>
> Michael.
> _______________________________________________
> Pas2js maillist?? -?? Pas2js at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20190904/8e6991d3/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.js
Type: application/x-javascript
Size: 42682 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20190904/8e6991d3/attachment-0001.bin>


More information about the Pas2js mailing list