Getting errors creating ChromiumOSR programmatically

青春壹個敷衍的年華 提交于 2019-12-04 07:14:14

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.

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;

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;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!