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.

How to instantiate and initialize TChromiumWindow while using DCEF4

Post Reply
neel
Posts: 2
Joined: Mon Jun 08, 2020 7:06 am

How to instantiate and initialize TChromiumWindow while using DCEF4

Post by neel »

Hello,
I am able to install DCEF4 package and run the sample projects successfully & sample projects are successfully showing the web pages.

I am creating my own sample using DCEF4 package but stuck with the question in the subject.

Below is my code from main program:
program Chrome_Browser;

uses
Vcl.Forms, uCEFApplication,
ChromeSample in 'ChromeSample.pas' {Form1};

{$R *.res}

begin
GlobalCEFApp := TCefApplication.Create;
if GlobalCEFApp.StartMainProcess then
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
end.

Below is the code from design unit:
unit ChromeSample;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uCEFWinControl, uCEFChromiumWindow,
Vcl.StdCtrls, Vcl.ExtCtrls;

type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Edit1: TEdit;
ChromiumWindow1: TChromiumWindow;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
ChromiumWindow1.LoadURL(Edit1.Text);
end;

end.
I am confused because, in the sample project 'simplebrowser.dpr' provided by briskbird, I did not find explicit object creation and initialization for
ChromiumWindow1: TChromiumWindow; yet that sample project works correctly.

In my sample project I even tried this, ChromiumWindow1:= TChromiumWindow(Form1) in the form show event but it did not help.

Pardon if I am missing something very obvious.

Thanks,
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to instantiate and initialize TChromiumWindow while using DCEF4

Post by salvadordf »

Hi,

You need to copy all events and procedures from the SimpleBrowser demo.

The browser need to call ChromiumWindow1.CreateBrowser in the TForm.OnShow event as you can see here :
https://github.com/salvadordf/CEF4Delph ... r.pas#L140

The timer will be used in case the first call to ChromiumWindow1.CreateBrowser in the OnShow event was not successful. This can happen if the OnShow was called before GlobalCEFApp.GlobalContextInitialized is set to true by CEF.
neel
Posts: 2
Joined: Mon Jun 08, 2020 7:06 am

Re: How to instantiate and initialize TChromiumWindow while using DCEF4

Post by neel »

Hello, Thanks for quick reply. After I copied the Timer and Form show events, my Sample app is working correctly now.
Post Reply