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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

best practice to add CEF4Delphi in a legacy application

Post Reply
francesco.faleschini
Posts: 22
Joined: Tue Nov 09, 2021 9:08 am

best practice to add CEF4Delphi in a legacy application

Post by francesco.faleschini »

Hi.

As anticipated in https://www.briskbard.com/forum/viewtopic.php?p=7583#p7583 I ask a question on the best practices by providing an example.

You can download from https://nextcloud.nordest.systems/s/4j98T8C859xRyF6/download a zip file that contains two projects.

There are 4 folders, 2 of them contain 2 projects:
Image

Please start with Demo Without DCEF: this is a minimalistic dummy project that represents a more complex application. The idea behind this project is to show a working application "before DCEF". The app starts by displaying a login form, then the main form with a browser tab that does not work (in the real case it was done with TWebBrowser but it makes no sense to do it in this sample so I did not add TWebBrowser).
Then a OpenCustomer button opens another form (that represents all the possible forms).
Please note that in this app all forms extend frroot.pas, so that this dummy app represents better my real world app.

Then check the Demo With DCEF: it is the same project as above but with DCEF added, in practice there are 2 places where a browser is added:
1) in the browser tab of the main form (it is possible to browse three hardcoded websites)
2) in the runtime attached page in the customer form (the browser displays a random URL)

Please be so kind to review my samples and reply to the following questions:
1) do you see any major problem in the DCEF implementation I did? Can you suggest a better approach, if any, for this type of application?
2) in the customer form with the current implementation I am not able to see the webpage (that is displayed on a runtime generated TabControlPage) unless I click on the runtime generated page, then I click on another page and finally again on the runtime generated page. I would expect to see the webpage the first time I click on the runtime generated page. Please check the code to see what's going on.
3) As I run the application I see in task manager two instances of SimpleBrowser_sp.exe (subprocess) , when in main form i go on the browser tab I see 4 instances and as I click on the 3 buttons that load other URLs I can have up to six instances but then again the number goes to four. If I open the customer form and go on the runtime generated page the number of instances is five and it returns to four as I close the form. Is this correct? I was expecting one instance per TChromiumWindow.

Please note I am using version 93 of Chromium, please have a look also at the uCEFLoader.pas unit where I assign the Browser subprocess path.

Thanks for reading, I understand there are a lot of questions, but I want to be sure what I am doing is right because I do not want to deliver to my end users something I am not 100% aware.

Bye!
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: best practice to add CEF4Delphi in a legacy application

Post by salvadordf »

I'll take a look at your demo in the weekend.
francesco.faleschini
Posts: 22
Joined: Tue Nov 09, 2021 9:08 am

Re: best practice to add CEF4Delphi in a legacy application

Post by francesco.faleschini »

Thanks a lot.

It is farily simple by the way.

I wait for your reply.

Have a great weekend.
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: best practice to add CEF4Delphi in a legacy application

Post by salvadordf »

Some suggestions :
  • TChromiumWindow is only intended for extremely simple browsers. Your application needs to show several browsers and it would make it easier for you in the future if you use a combination of TChromium and TCEFWindowParent.
  • If all you need in this application is to show browsers as child forms then I would suggest that you use the code from the ToolBoxBrowser demo. Using the code from that demo will fix the second issue.
  • Chromium requires to follow some destruction steps before terminating the application. Read the code comments in uChildForm.pas and uMainForm.pas for all the details. Basically, you need to close all the browser forms correctly before you close the main form.
  • As a result of the previous suggestion, the "Application.terminate" call in the FormClose event must be removed.
  • If you want to add some tabs with embedded browsers then I would also suggest to use the code from TabbedBrowser2 demo. It uses frames with browsers. In this case, the application would have to close all the browsers found in child forms and tabs before closing the main form.
The number of subprocesses is controlled internally by Chromium and it creates them for other tasks different that rendering a new tab and sometimes it reuses old processes.
francesco.faleschini
Posts: 22
Joined: Tue Nov 09, 2021 9:08 am

Re: best practice to add CEF4Delphi in a legacy application

Post by francesco.faleschini »

Hi.

Thanks a lot for your reply, I studied it with attention and I tried to implement ToolBoxBrowser demo approach (I made a new version of it, the project is in the zip file at Sample Projects V2\Demo With DCEF V2\DCEFDemo.dpr).

You can download the zip from https://nextcloud.nordest.systems/s/ps5WptKzk7L8iAe

The main difference is that I changed the part that destroys the components: instead of using the message based approach (CEFBROWSER_DESTROY) I explicitly freed what needed to be freed since this approach suits my real case better.

I think that by implementing what you suggested now I have a more reliable result.

If you take the time to review my modified example I would appreciate it a lot.

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

Re: best practice to add CEF4Delphi in a legacy application

Post by salvadordf »

I'll try to make some time for it in the weekend.
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: best practice to add CEF4Delphi in a legacy application

Post by salvadordf »

Sorry for the delay. I just saw your demo and it works fine.

The destruction sequence of the child forms is different than the usual but it seems to work fine.
Post Reply