Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on LoadURL with TChromium

I found the brilliant Delphi Chromium project for embedding Chrome in a Delphi form. It works well in Delphi7 after a bit of hacking and I can get the demo app running.

However when I do my own app with the component, I can't load my own url. I get a access violation.

Chromium2.Browser.MainFrame.LoadUrl('http://www.example.com');

The TChromium component is working and I have all the DLLs in the right place, since if I set DefaultUrl it works fine.

I have Chromium2 in a TPageControl page and with the OnClick event of a button I call the above code. I get an AccessViolation. Mainframe is nil.

I can't find a way around this, has anyone got this to work?

like image 603
Toby Allen Avatar asked Jan 18 '23 17:01

Toby Allen


2 Answers

I still haven't found a resolution but I found the following work around

procedure TForm1.lblWebsiteClick(Sender: TObject);
var MainFrame : ICefFrame;
begin
  MainFrame := Chromium2.Browser.GetMainFrame;
  MainFrame.LoadUrl('http://www.cookingisfun.ie');
end;
like image 149
Toby Allen Avatar answered Jan 27 '23 02:01

Toby Allen


The problem is that mainframe only loads after the page has loaded.

For one thing, you need to do:

if Assigned(Chromium2.Browser.MainFrame)
    then  Chromium2.Browser.MainFrame...

However, that is not the preferred way to navigate, but instead you should do:

Chromium1.Load( theUrl );

If you still want to use MainFrame, do it in OnLoadEnd event.

like image 36
Christian Avatar answered Jan 27 '23 01:01

Christian