TChromium 中的默认界面缺失
我们正在尝试将内置浏览器组件从 TWebBrowser 更改为 TChromium。 它主要用于显示 Google 和 Bing 的地图。从 javascript 到 Delphi 的通信是通过 COM 完成的。
当尝试将浏览器更改为 TChromium 时,无法编译此代码。
if supports(fBrowser.defaultInterface, IOleObject, fOLE) then
因为 TChromium 中缺少 defaultInterface。
编辑: 是否仍然可以使用 Chromium 从 javascript 到 Delphi 进行通信? 我知道它们不兼容,我必须重写代码。我只是想知道如何从 javascript 获取结果到 delphi。注意我使用的是 Delphi 2007,因此无法使用扩展 RTTI。
问候 罗兰·本特松
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己从未使用过它,但
TChromium
似乎是“Chromium”网络浏览器的包装器,而 Delphi 的原始TWebBrowser
是 IE 浏览器的包装器。TWebBrowser.defaultInstance
为您提供 IE 浏览器的 COM 对象。对于 Chromium 浏览器,您显然可以使用TChromium.Browser
,它为您提供一个ICefBrowser
类型的对象。TChromium
人员很聪明,没有将属性命名为defaultInstance
,因为有很多代码从defaultInstance
的返回转换为其他接口类型:如果TChromium.Browser
命名相同,则转换将编译并在运行时失败。因为IE浏览器显然不是Chrome浏览器,而且我怀疑Chromium浏览器完全实现了所有IE接口。I never used it myself, but
TChromium
appears to be a wrapper around the "Chromium" web browser, while the originalTWebBrowser
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 useTChromium.Browser
, it gives you an object of typeICefBrowser
. TheTChromium
people were smart not to name the propertydefaultInstance
because there's a lot of code out there casting from the return ofdefaultInstance
to other interface types: IfTChromium.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.使用TChromium,您可以通过
ExecuteJavaScript
轻松调用脚本。您还可以从脚本调用 Delphi 代码,您可以使用脚本将返回值从 JavaScript 函数发送回 Delphi。请参阅这个问题以及我对使用扩展程序执行此操作的回答。
像 EexecuteScriptAndReturnValue 这样的函数似乎也在进行中,但在撰写本文时,它们尚未包含在主干中。
关于
TWebBrowser.DefaultInterface
我同意 Cosmin 的观点:最好的类比可能是TChromium.Browser
因为您可以从那里访问框架以及随后的 DOM 等。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 probablyTChromium.Browser
as you can access frames and subsequently DOM, etc. from there.