以编程方式创建ChromiumOSR时出错 [英] Getting errors creating ChromiumOSR programmatically

查看:112
本文介绍了以编程方式创建ChromiumOSR时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式创建ChromiumOSR,但始终出现错误(访问冲突)。
以下是导致问题的示例代码:

I'm trying to create ChromiumOSR programmatically 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?)

推荐答案

您尝试使用 Load 方法加载页面是正确的。另一个错误并失败,因为未创建 Browser 实例。这是因为 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.

现在, 浏览器实例创建的唯一位置是 Loaded 方法,该方法在其父窗体为从流中加载。并且由于您是动态创建的,因此永远不会创建 Browser 实例。

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 方法(创建 Browser 实例)被声明为私有,这使它的调用有点复杂(除非您决定修改来源并将其公开)。如果您不想更改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;

然后创建 Browser 实例,添加在第一次访问 Browser 实例(此处为 Load CreateBrowserInstance 调用c $ c>方法):

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆