Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

DoOnLoadStart/doOnLoadEnd doesn't work.

Post Reply
Rockiman
Posts: 6
Joined: Wed Jun 06, 2018 12:11 pm

DoOnLoadStart/doOnLoadEnd doesn't work.

Post by Rockiman »

Hi, I programmatically create a browser and try to use doOnLoadStart/doOnLoadEnd procedure, but it is never called. In the same time, for example, function doOnGetResourceHandler works normally. What is the problem?

Code: Select all

unit cef4exp1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uCEFWindowParent, uCEFChromiumWindow,
  uCEFChromium, uCEFInterfaces, uCEFConstants, uCEFTypes, Vcl.StdCtrls;

type
  chrome = class(TChromium)
  private
  public
    procedure doOnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: TCefTransitionType);override;
  end;

type
  TForm1 = class(TForm)
    CEFWindowParent1: TCEFWindowParent;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
  end;

var
  Form1: TForm1; ch:chrome;

implementation


{$R *.dfm}

procedure chrome.doOnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: Cardinal);
begin
 form1.Caption:='Procedure works';
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 ch:=chrome.Create(Form1);
 ch.CreateBrowser(CEFWindowParent1);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if ch.Initialized then ch.LoadURL('google.com');
end;

end.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: DoOnLoadStart/doOnLoadEnd doesn't work.

Post by salvadordf »

Hi,

The short answer for that is this :
Override TChromium.MustCreateLoadHandler and set the result to TRUE. After that, doOnLoadStart and doOnLoadEnd will work.

The long answer is this :
TChromium only creates what's needed. When your application calls TChromium.CreateBrowser it checks what events are really used and then it creates the "handlers" that are needed to make those events work.

There are a bunch of virtual functions called "TChromium.MustCreate********Handler" that check what TChromium events are used. In this case, you want to create ICefLoadHandler even if there are no events used so you need to override TChromium.MustCreateLoadHandler and set the result to TRUE.
Rockiman
Posts: 6
Joined: Wed Jun 06, 2018 12:11 pm

Re: DoOnLoadStart/doOnLoadEnd doesn't work.

Post by Rockiman »

Ok, got that, thank you for answer. :)
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: DoOnLoadStart/doOnLoadEnd doesn't work.

Post by salvadordf »

Assign the event you need before calling TChromium.CreateBrowser at runtime and everything will be ok.
Post Reply