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.

TChromium vs C++ Builder

Post Reply
Pieter E.
Posts: 12
Joined: Thu Oct 19, 2017 2:47 pm

TChromium vs C++ Builder

Post by Pieter E. »

I'd like to try your CEF4Delphi component. I'm using C++ Builder XE3. I can't make it work.

I've created a TChromium and TCEFWindowParent component on a TForm. My code is as followed:

Code: Select all

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TChromium *Chromium;
TCEFWindowParent *CEFWindowParent;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
  CEFWindowParent = new TCEFWindowParent(this);
  CEFWindowParent->Parent = this;
  CEFWindowParent->Align = alClient;
  CEFWindowParent->Visible = true;

  Chromium = new TChromium(this);
  Chromium->OnAfterCreated = ChromiumAfterCreated;
  Chromium->CreateBrowser(CEFWindowParent, "");
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ChromiumAfterCreated(System::TObject* Sender, const Ucefinterfaces::_di_ICefBrowser browser)
{ 
  // FOUND THIS CODE IN A SAMPLE FILE. NOT SURE WHAT IT DOES...
  PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Chromium->LoadURL("https://www.google.com/");
}
//---------------------------------------------------------------------------
I copied all the necessary win32 files to the same location where the executable is published. When running my project TCEFWindowParent is created but nothing else seems to happen. Probably I did something wrong.

Can you please inform me what's wrong? Thank you in advance!
Pieter E.
Posts: 12
Joined: Thu Oct 19, 2017 2:47 pm

Re: TChromium vs C++ Builder

Post by Pieter E. »

I did some digging and found the following Japanese website: http://mrxray.on.coocan.jp/Delphi/plSam ... Delphi.htm

I found out that some code was missing in the main project file. I added the missing code which results in:

Code: Select all

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <tchar.h>

#include "uCEFApplication.hpp"
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form1);

#define SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE
//---------------------------------------------------------------------------
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
	try
	{
		GlobalCEFApp = new TCefApplication(false);
		GlobalCEFApp->FrameworkDirPath = "cef";
		GlobalCEFApp->ResourcesDirPath = "cef";
		GlobalCEFApp->LocalesDirPath = "cef\\locales";
		GlobalCEFApp->Cache = "cef\\cache";
		GlobalCEFApp->Cookies = "cef\\cookies";
		GlobalCEFApp->UserDataPath = "cef\\User Data";

		if(GlobalCEFApp->StartMainProcess())
		  {
			Application->Initialize();
			Application->MainFormOnTaskBar = true;
			Application->CreateForm(__classid(TForm1), &Form1);
			Application->Run();
		  }
		GlobalCEFApp->Free();
	}
	catch (Exception &exception)
	{
		Application->ShowException(&exception);
	}
	catch (...)
	{
		try
		{
			throw Exception("");
		}
		catch (Exception &exception)
		{
			Application->ShowException(&exception);
		}
	}
	return 0;
}
//---------------------------------------------------------------------------
The following files are added to the cef folder

Code: Select all

24/10/2017  20:39    <DIR>          .
24/10/2017  20:39    <DIR>          ..
24/10/2017  20:26    <DIR>          cache
30/09/2017  09:44         4,131,368 cef.pak
30/09/2017  09:44           573,159 cef_100_percent.pak
30/09/2017  09:44           665,519 cef_200_percent.pak
30/09/2017  09:44         3,320,784 cef_extensions.pak
30/09/2017  09:43       159,277,434 cef_sandbox.lib
30/09/2017  09:44           471,552 chrome_elf.dll
24/10/2017  20:26    <DIR>          cookies
30/09/2017  09:44         2,106,216 d3dcompiler_43.dll
30/09/2017  09:44         3,747,512 d3dcompiler_47.dll
30/09/2017  09:44         5,353,454 devtools_resources.pak
30/09/2017  09:44        10,197,040 icudtl.dat
30/09/2017  09:44        85,383,168 libcef.dll
30/09/2017  09:44            54,056 libcef.lib
30/09/2017  09:44            79,872 libEGL.dll
30/09/2017  09:44         4,080,640 libGLESv2.dll
24/10/2017  20:26    <DIR>          locales
30/09/2017  09:44           221,973 natives_blob.bin
30/09/2017  09:44         2,138,088 snapshot_blob.bin
24/10/2017  20:26    <DIR>          User Data
30/09/2017  09:44           215,040 widevinecdmadapter.dll
              19 File(s)    282,016,899 bytes
After executing the application still nothing happens. Can you please help me out?
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromium vs C++ Builder

Post by salvadordf »

Hi Pieter,

Another user called ddrmax used C++ builder 2009 successfully with CEF4Delphi. This thread may give you some hints :
https://www.briskbard.com/forum/viewtop ... f=10&t=152

Windows and Delphi don't like to create and destroy components in different threads or processes, and all the TChromium events are executed in threads and processes different than the main thread and process.

For that reason you will see some messages posted to the form from the TChromium events or comments indicating that you should use critical sections or mutexes. That way you ensure that all components are created and destroyed in the main thread and avoid race conditions.

The CEF_AFTERCREATED message is sent to the main form to load the first web page. It indicates that the TChromium is fully initialized. If you try to load a web page before receiving CEF_AFTERCREATED you will see nothing.

The MiniBrowser demo executes the BrowserCreatedMsg procedure when the CEF_AFTERCREATED is received and it does several important things :
  • It calls CEFWindowParent1.UpdateSize because sometimes the CEFWindowParent needs to update the size of the browser.
  • Some UI components are enabled here to avoid using the browser before it's fully initialized.
  • The homepage is loaded.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromium vs C++ Builder

Post by salvadordf »

I forgot to add that you need to read this web page too :
https://www.briskbard.com/index.php?lang=en&pageid=cef

It has very important information and links to the github repository, CEF3 documentation, etc.
Pieter E.
Posts: 12
Joined: Thu Oct 19, 2017 2:47 pm

Re: TChromium vs C++ Builder

Post by Pieter E. »

Thank you for helping me out. TChromium works like a charm! :D :D :D
AndreMurta
Posts: 6
Joined: Thu Apr 12, 2018 1:51 am

Re: TChromium vs C++ Builder

Post by AndreMurta »

Hi guys, I know this post is a little bit old now, but did any of you had success in use the Chromium webkit in C++ Builder? It seems, comparing the NinjaBrowser C++ code with the CEF4Delphi examples, the way to use the webkit it will differ from the Delphi code. I would like to extend the NinjaBrowser with some JS Extensions. Made some attempts by myself but without success.
Post Reply