Page 1 of 1

Simplest way...

Posted: Thu Jul 09, 2020 2:50 pm
by dvhooren
Hi,

I am trying to find the minimum number of lines to go to a website.

I have this:
- Chromium1
- ChromiumWindow1

Then in code I do this:

Chromium1.CreateBrowser(ChromiumWindow1);
ChromiumWindow1.LoadURL('https://www.google.nl');

For my understanding:
If I create a browser when the application is started why should I then so often use CreateBrowser?

Often I note that LoadUrl does nothing.

I miss something.

Greetings Danny..

Re: Simplest way...

Posted: Thu Jul 09, 2020 3:36 pm
by salvadordf
Hi,

Chromium and CEF require some steps to be initialized.

That initialization process uses several processes and threads, which makes it a little bit more complicated.

The CEF4Delphi components facilitate that initialization process to some extent but it's necessary to call a few procedures and wait for some other conditions before you can load a URL.

TChromium and TCEFWindowParent are the basic components used to add a browser. TChromiumWindow is just a combination of TChromium and TCEFWindowParent but it should only be used in extremely simple browsers.

TChromium has all the procedures, methods and events to handle a web browser. I guess you can consider it a "browser controller". All these procedures, functions and events are in fact functions and callbacks in the CEF API.

TCEFWindowParent is used by CEF as a dumb parent. CEF will create child controls inside TCEFWindowParent and those child controls will be used to draw the browser contents.

Those controls don't create the web browser automatically because there are some situations where you don't want to create the browser immediately.

The basic steps to create a browser in your main form would be :
  • Create GlobalCEFApp
  • Set some custom properties in GlobalCEFApp
  • Call GlobalCEFApp.StartMainProcess. This procedure creates other processes and threads. One of those threads creates a "global context" asynchronously that needs to be fully initialized before creating your first web browser.
  • Create the main form in your application and call TChromium.CreateBrowser. This function will only work when the global context is initialized (GlobalCEFApp.GlobalContextInitialized = TRUE).
  • TChromium triggers the TChromium.OnAfterCreated event when this browser is fully initialized.
To load the first URL as soon as TChromium is initialized you can set the TChromium.DefaultURL property before the TChromium.CreateBrowser call. If you don't use that property you can call TChromium.LoadURL after the TChromium.OnAfterCreated event has been triggered.