以编程方式获取创建ChromiumOSR的错误 [英] Getting errors creating ChromiumOSR programatically
问题描述
我正在尝试以编程方式创建ChromiumOSR,但我不断收到错误(访问冲突)。
这是导致问题的示例代码:
I'm trying to create ChromiumOSR programatically but I keep getting an error (access violation). Here is sample code that causes the problem:
var
pChromiumOSR: TChromiumOSR;
begin
pChromiumOSR := TChromiumOSR.Create(Self);
pChromiumOSR.OnLoadEnd := pChromiumOSRLoadEnd;
pChromiumOSR.Browser.MainFrame.LoadUrl('www.google.com');
end;
问题是pChromiumOSR.Browser.MainFrame总是为零。如果我做
pChromiumOSR.load('www.google.com');我没有得到任何错误,但它不会触发onLoadend。
The problem is that pChromiumOSR.Browser.MainFrame is always nil. If I do pChromiumOSR.load('www.google.com'); I don't get any errors but it doesn't fire the onLoadend.
有谁可以给我任何建议,我可能做错了什么?
我正在使用Delphi XE2,但不知道哪个版本的铬(在哪里可以找到版本?)
Can anyone give me any suggestions on what I might be doing wrong? I'm using Delphi XE2 but not sure which version of chromium (where can I find the version?)
感谢您的帮助。
推荐答案
您尝试使用加载
加载页面的方法是正确的。另外一个是错误的,因为没有创建浏览器
实例。这是因为 TChromiumOSR
被设计为设计时间组件,而不是动态创建。
Your attempt to use Load
method for loading a page was correct. The other one was wrong and failed because the Browser
instance was not created. It's because the TChromiumOSR
was designed to be a design time component rather than to be created dynamically.
现在,只有创建浏览器
实例的地方是加载的
方法,该方法在其父表单为从流加载。而且,由于您正在动态创建它,所以从未创建浏览器
实例。
Now, the only place where the Browser
instance is created is the Loaded
method, which is called for a component after its parent form is loaded from a stream. And since you are creating it dynamically, the Browser
instance is never created.
由于某些原因, CreateBrowser
方法(其创建浏览器
实例)被声明为私有,这使其调用变得复杂(除非您决定修改来源并使其公开)。如果您不想更改DCEF源代码,可以使用类帮助程序来访问 CreateBrowser
方法:
For some reason also the CreateBrowser
method (which creates the Browser
instance) is declared as private, which complicates its calling a bit (unless you decide to modify the source and make it public). If you don't want to change your DCEF source code, you can use a class helper to provide access to the CreateBrowser
method:
uses
ceflib, cefvcl;
type
TChromiumOSRHelper = class helper for TCustomChromiumOSR
public
procedure CreateBrowserInstance;
end;
implementation
{ TChromiumOSRHelper }
procedure TChromiumOSRHelper.CreateBrowserInstance;
begin
Self.CreateBrowser;
end;
然后创建一个浏览器
实例添加 CreateBrowserInstance
在首次访问浏览器
实例之前调用(这里是 Load
方法):
Then to create a Browser
instance add the CreateBrowserInstance
call before the first accessing the Browser
instance (which is here the Load
method):
var
pChromiumOSR: TChromiumOSR;
begin
pChromiumOSR := TChromiumOSR.Create(Self);
pChromiumOSR.OnLoadEnd := pChromiumOSRLoadEnd;
pChromiumOSR.CreateBrowserInstance;
pChromiumOSR.Load('www.google.com');
end;
这篇关于以编程方式获取创建ChromiumOSR的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!