如何使用NPAPI将Delphi VCL表单嵌入HTML页面? [英] How to embed Delphi VCL form into HTML page using NPAPI?

查看:500
本文介绍了如何使用NPAPI将Delphi VCL表单嵌入HTML页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Delphi编写ActiveX插件有一些已知的方法,但ActiveX本身在除IE之外的浏览器中有很大的局限性。所以我在想 - 如何编译一个NPAPI格式的插件,原生兼容Chrome / Firefox?



插件的意图是允许将VCL表单嵌入到HTML页面,并能够使用JavaScript双向通信此表单。例如。单击表单上的按钮将调用页面上的JavaScript函数,页面上的JavaScript函数可以将事件发送到VCL表单。如何实现?

解决方案

Mozilla bugtracker中有一个Delphi的现有NPAPI包装器列表: https://www.mozdev.org/bugs/show_bug.cgi?id=8708



最新的条目(具有脚本支持的NPAPI插件框架,Yury Sidorov的演示)提供了所需要的。



使用该VCL Form项目可以编译成与NPAPI兼容的DLL。 Manifest.json也需要添加。之后,插件可以像平常一样安装到Chrome中。



以下HTML代码嵌入了存储在插件中的VCL表单:

 < EMBED id =embed1TYPE =application / x-delphi-demo-pluginALIGN = CENTER WIDTH = 400 HEIGHT = 300& 

< script>
var embed1 = document.getElementById('embed1');
< / script>

< input type = button value =显示值onclick ='alert(Value =+ embed1.value);'>

这就是Form可以改变HTML页面:

  with Plugin.GetBrowserWindowObject do 
GetObject('document')['bgColor']:= clRed;

应用于现代Delphi版本的唯一修复 - 将 string PChar 更改为 AnsiString PAnsiChar 整个 NPPlugin.pas 。否则与嵌入式表单的通信已损坏。


There are known ways of writing ActiveX plugins with Delphi, but the ActiveX itself poses a lot of limitations in browsers other than IE. So I was thinking - how to compile a plugin in NPAPI format, natively compatible with Chrome/Firefox?

Intent of the plugin is to allow to embed a VCL form into the HTML page and be able to bi-directionaly communicate with this form using JavaScript. E.g. clicking a button on a form would call JavaScript function on the page, and JavaScript functions on the page could send events to a VCL form. How this can be achieved?

解决方案

There's a list of existing NPAPI wrappers for Delphi at Mozilla bugtracker: https://www.mozdev.org/bugs/show_bug.cgi?id=8708

The latest entry (NPAPI plugin framework with scripting support + demo by Yury Sidorov) offers exactly what is needed.

With that VCL Form project can be compiled into a DLL compatible with NPAPI. Manifest.json also needs to be added. Afterwards the plugin can be installed into Chrome like usual.

Following HTML code embeds the VCL form that is stored in the plugin:

<EMBED id="embed1" TYPE="application/x-delphi-demo-plugin" ALIGN=CENTER WIDTH=400 HEIGHT=300>

<script>
var embed1 = document.getElementById('embed1');
</script>

<input type=button value="Show Value" onclick='alert("Value=" + embed1.value);'>

And that is how Form can change the HTML page around it:

with Plugin.GetBrowserWindowObject do
  GetObject('document')['bgColor'] := clRed;

P.S. The only fix that should be applied for modern Delphi versions - change string and PChar to AnsiString and PAnsiChar throughout the NPPlugin.pas. Or else communication with embedded form is broken.

这篇关于如何使用NPAPI将Delphi VCL表单嵌入HTML页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆