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

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.

Related

HTML5 canvas animation with Delphi

I need to replace a Flash animation in a Delphi application. So far I have used a TShockwaveFlash component to load an SWF file. Used Adobe Animate to convert this SWF file into an HTML 5 canvas and changed some syntax for the action script.
The output from Adobe Animate is the following:
.html
.js
images/.png
How do I integrate these into my Delphi application to replace the old Flash animation? Not very experienced in web development.
We installed WebView2 and used the TEdgeBrowser component.
You can access the script part in delphi in this way:
var Script: string := componentname+'.Enable.gotoAndStop(0);';
EdgeBrowser1.ExecuteScript(Script);

delphi xe8 + twebbrowser : how to use Jquery inside to communicate?

My goal is to create a delphi XE8 project (VCL or fireMonkey) that will interact with webbrowser.
I want to use the power of JS (jquery) to access DOM, extract some data and send them back to delphi.
I try to use twebbrowser and... any page gives me tons of JS errors : I think twebbroser is based on a very old browser such as Internet explorer8
I run windows7 + IE11
1) Should I go to chromium browser ? (Tchromoium or chromiumembedded ?)
2) How to make it communicate with Jquery ?
Regards

Delphi using Microsoft’s Shell Doc Object and Control Library (SHDOCVW.DLL)

Can someone provide some background on the TWebBrowser component with regards to HTML/CSS standards? I am puzzled why it is that despite the fact that I am using Windows 7, with IE 8 installed, that I get different rendered results when displaying a HTML file in IE8 versus what I see when the same HTML file is displayed within TWebBrowser. For instance, pseudo elements p:before and p:first-letterare totally ignored in the CSS file when the HTML file is viewed in TWebBrowser (Delphi 7), yet they are honored when the same HTML file is viewed in IE8.
Is the SHDOCVW.DLL perhaps so old that I am in affect getting IE3 rendering? I'm trying to wrap my head around why IE8 frequently renders HTML considerably different than what one gets when using TWebBrowser.
IE8 renders pages running within instances of the WebBrowser control in IE7 Standards Mode by default. The difference that you see is therefor based on the difference of the IE8 & IE7 standard.
When an executable loads an instance of the WebBrowser control it scans the registry to check whether the executable wants IE7 Standards or IE8 Standards mode.
WebBrowser Control Rendering Modes in IE8(deprecated)
WebBrowser Control Rendering Modes in IE8(Updated)
To run a WebBrowser control in IE7 Standards Mode, insert the following values into the registry:
[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"MyApplication.exe" = dword 7000 (Hex: 0x1B58)
To run in IE8 Standards Mode insert the following registry value:
[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"MyApplication.exe" = dword 8000 (Hex: 0x1F40)
In both of these instances, MyApplication.exe should be replaced with the name of the executable that will be running WebBrowser controls in a specified mode.
That much said, you can avoid fiddling with the registry all together.
Pages hosted in a WebBrowser control can override rendering settings by using the X-UA-Compatible meta tag to specify a rendering mode.
for example, to force IE8 TWebBrowser control to render site in IE8 standard use:
<META http-equiv="X-UA-Compatible" content="IE=8">
This can be done globally via a host-header or as a per-document edit.
the Meta tag solution might be deprecated, I would suggest you follow the registry steps.

Which are the basic guidelines for using Delphi IntraWeb with Twitter Bootstrap?

I would like to use the Bootstrap Framework with Delphi's IntraWeb (I'm using XE2)? The idea is to have the server side logic done by Delphi, while using the nice controls that come with BootStrap?
What would be the basic components "Hello World" application for this configuration?
What would be the high-level approach for a more elaborate application, for example one with a Bootstrap nav component that has its tab contents populated by Delphi?
Is combining IntraWeb and Bootstrap an overkill? Would I would be better off with an Indy TIdHTTPServer + Bootstrap?
It does not have to be difficult to implement Boostrap with Intraweb, you just have to add the Js files in the ContentFiles property of the IWForm, you just have to take in mind you have to write the html for each component you use for BootStrap.
In http://www.codegearguru.com in the Movie #63 - Using jQuery Mobile with IntraWeb - CodeRage 6 Replay
They have explained how to develope the Fishfact demo using jQueryMobile, using the TIWTemplateProcessorHTML component and standard IW components, so it should no be difficult to adapt it for bootstrap.
Here is the link: http://codegearguru.com/video/063/jQueryMobileFishFacts.html
Althought, there have been a new component suite since last year implementing JQuery and jQuery mobile, you should take a loo at http://www.cgdevtools.com, I'm using them and let me tell it give you IW app a very nice view. AFAIK they are planning to generate a component suite for Bootstrap.
As far as the web-server is concerned, it should provide the necessary files when the client requests them to run bootstrap client-side: Bootstrap: File Structure
To populate the components (client-side), you'll have to create the server-side logic so it will enter the correct javascript that does so into the HTML of the pages.

Defaultinterface in TChromium is missing

We are trying to change the builtin browser component from TWebBrowser to TChromium.
It is used mostly for displaying maps from Google and Bing. The communication from the javascript to Delphi is done with COM.
When trying to change the browser to TChromium it fails to compile this code.
if supports(fBrowser.defaultInterface, IOleObject, fOLE) then
because defaultInterface is missing from TChromium.
EDIT:
Is it possible to still communicate from javascript to Delphi with Chromium?
I'm aware of that they are not compatible and I have to rewrite code. I just want to know how to get a result from javascript to delphi. Note I am using Delphi 2007 so the extended RTTI cannot be used.
Regards
Roland Bengtsson
I never used it myself, but TChromium appears to be a wrapper around the "Chromium" web browser, while the original TWebBrowser from Delphi is a wrapper around an IE Browser.
TWebBrowser.defaultInstance gives you the COM object of the IE Browser. For the Chromium browser you can apparently use TChromium.Browser, it gives you an object of type ICefBrowser. The TChromium people were smart not to name the property defaultInstance because there's a lot of code out there casting from the return of defaultInstance to other interface types: If TChromium.Browser was named the same, the cast would compile and fail at run time. Because the IE Browser is obviously not a Chrome browser, and I doubt the Chromium browser fully implements all IE interfaces.
Using TChromium, you can invoke scripts easily via ExecuteJavaScript. And you can invoke Delphi code from scripts, which you can use to send return values back from a JavaScript function to Delphi.
See this question and my answer there about doing this using extensions.
There also seems to be work in progress for functions like EexecuteScriptAndReturnValue but as the time of writing they are not contained in the trunk.
And regarding TWebBrowser.DefaultInterface I agree with Cosmin: the best analogy is probably TChromium.Browser as you can access frames and subsequently DOM, etc. from there.

Resources