Creating NPAPI plugin in Delphi and accessing exported APIs using javascript

家住魔仙堡 提交于 2019-12-11 00:41:29

问题


I have found a useful billards physics library in Borland delphi for my hobby project. The code is object oriented(in Object pascal). I want to visualize it using webGL (javascript) in chrome browser.

The idea is, I should have one call to make from the javascript which will access the interface from delphi lib and give me the new position, rotation and scale values in respective array.

For this I want to develop an NPAPI lib Scriptable plugin in Delphi(Meaning NO UI only lib of APIs).

1)I want to export those necessary physics APIs from the Delphi via this NPAPI plugin and access them in my html page using JavaScript. I am targeting chrome. 2) Any simple "hello world" tutorial or article related to this will be highly helpful.

3)Any help on using Firebreath to achieve the same is most preferable. How to use Delphi with Firebreath?


回答1:


  • use a good HTML / JavaScript editor (for example the NetBeans IDE) create a basic HTML page which contains the "hard-coded" JavaScript to display the initial scene, and a HTML form to accept user input

  • use Indy or Synapse to create a HTTP server (in Delphi), wich serves this HTML page and when the user submits form input, parse the form parameters and pass them to the billiard simulation, which should emit a list of graphic commands as a result - and convert these to WebGL (this is the hard part) statements

  • from the HTTP server, send a response (HTML document) back to the client, with the JavaScript / WebGL statements embedded, so that the client will see the animation and the new playfield state

  • repeat until end of game




回答2:


Create a COM DLL and install it on the client's machine. Then Javascript can use its ActiveXObject class to access the COM object (or, under IE, you can use the <object> HTML tag). Make sure your COM object implements the IDispatch interface, as Javascript needs to use late binding since it is an interpretted environment and not compiled.



来源:https://stackoverflow.com/questions/8862628/creating-npapi-plugin-in-delphi-and-accessing-exported-apis-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!