I have a navbar gallery on a Frame. When I press e.g. button 2 I want that the Delphi method RenderPage (2) is called. How can I implement that a Delphi method is assigned as a callback from an HTML event? My HTML code looks the following: html := html +
'' +
i.ToString + '';
The RenderPage method already exists in my Delphi code, but how to access from HTML/JS?
And how is it possible to give extra information? I need to know which button was pressed. Otherwise I need to give each button its own callback. But there could be 20 buttons …
Apparantly the example code send in my first call wasn’t show properly but interpreted as html..
Having replaced <> by square brackets, I want something like this:
HTML code:
[li class="page-item"> [a class="page-link" href="#" onclick="pascal.RenderPage(1)"]1[/a>][/li]
[li class="page-item"> [a class="page-link" href="#" onclick="pascal.RenderPage(2)"]2[/a>][/li]
and so on.
And RenderPage (PageNum: Integer) is the method I want to call from my JS/html.
First thank for all you help. I will send you a separate mail.
The answer I was looking for I found on StackOverflow and is: I can call a Delphi method of a certain Delphi Object by the following JS/HTML: code:
[a onclick=”pas.. ()”]
So I made it as follows: [a onclick=”pas.UViewer.FViewerFrame.RenderPage(1)”] for the button that must render the first page.
Remains one question: Now I referred to a Frame that was created at starttime of the application and has a fixed reference in the unit (e.g: var Form1: TForm1). But how could I have linked this to the JS object in which the HTML element was ‘executed’. Since not always a (‘static’) Delphi object is available. Could I have linked to something like: js.this.RenderPage (1)?
Second question: could I have found this info (how to call Delphi methods from JS: through the pas. namespace) in the (extensive) documentation? I thought I had searched thoroughly, but possibly I missed something.
I think the StackOverflow answer is based on pas2js documentation. This approach is not in our documentation and not anywhere in our code.
I have personally not used this approach. I have always used the approach that I recommended in my first answer.