2

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

Roland Bengtsson
  • 5,058
  • 9
  • 58
  • 99
  • Are you sure that `TChromium` even supports `IOleObject`? – David Heffernan Jul 27 '11 at 11:46
  • 1
    Chromium probably doesn't support `IOleObject`. What are you using `TWebBrowser.DefaultInterface` for? If you have a specific problem try to describe it in more detail. Perhaps it's possible to achieve the same result with Chromium in a different way. – Ondrej Kelle Jul 27 '11 at 11:51
  • I second TOndrej's suggestion. If "Chromium" has anything to do with the "Chrome" browser, then it's very likely to support anything you might want to do. But it's definitively not a drop-in replacement for `TWebBrowser`. Ie: copy-pasted code designed for TWebBrowser will not work. – Cosmin Prund Jul 27 '11 at 12:00

2 Answers2

5

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Cosmin Prund
  • 25,498
  • 2
  • 60
  • 104
  • Yes, that what I suspected. But it should be some way to communicate between javascript and Delphi ? – Roland Bengtsson Jul 27 '11 at 11:57
  • As I've said, I haven't used TChromium myself. I simply looked at some of the source files on it's [code.google.com/p/delphichromiumembedded/](http://code.google.com/p/delphichromiumembedded/) repository. There's no documentation over there, and I can't judge the quality of the in-source comments. Your best bet is to use the information from here: http://code.google.com/p/chromiumembedded/ because that's what TChromium is wrapping. – Cosmin Prund Jul 27 '11 at 12:06
  • Have a look at and experiment with `TCefRTTIExtension`. From what little I understood from the code so far, it declares a native extension to the V8 Javascript engine and seems to use RTTI to resolve property and method names to invoke your Delphi code. – Ondrej Kelle Jul 27 '11 at 12:13
  • 3
    http://groups.google.com/group/delphichromiumembedded/browse_thread/thread/1793e7ca66012f0c – Henri Gourvest Jul 27 '11 at 12:41
  • It seems that it is easier with D2010 and extended RTTI. Unfortunately I use D2007 and I cannot upgrade now until Bold for Delphi is rewritten for Unicode. – Roland Bengtsson Jul 28 '11 at 06:39
  • Yes it's easier with D2010 and higher but still possible with D2007. Have a look at `cefclient.dpr` and how `TExtension` is used there. – Ondrej Kelle Jul 28 '11 at 08:18
1

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.

Community
  • 1
  • 1
Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85