How to embed Delphi VCL form into HTML page using NPAPI?

后端 未结 1 1444
臣服心动
臣服心动 2021-01-28 19:36

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 pl

相关标签:
1条回答
  • 2021-01-28 20:03

    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.

    0 讨论(0)
提交回复
热议问题