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.defa开发者_开发技巧ultInterface, 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.
精彩评论