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.

Risks of including CEF4Delphi in an existing project

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

Risks of including CEF4Delphi in an existing project

Post by francesco.faleschini »

Hi.

I am a new forum user and also I just started using CEF4Delphi.

The reason why I started adopting it is that I would like to show modern html5 web pages (that TWebBrowser cannot handle) in my win32 application.

Basically what I plan to do is to have a frame that contains the browser window and to use this frame in several parts of the application (basically in page control's tabs, in modal windows, ...). I designed a framework to create the web pages I need and I use CEF4Delphi to display them in my legacy application.

My application is a quite old win32 client/server legacy application (you can say it is a kind of ERP), with this new approach I plan to make customization simpler for my users: before all UI was hardcoded, now the browser based UI parts somehow are customization. So basically my users will be able to see "New UI parts" that are provided by a custom web application and the Delphi exe, through CEF4D, is able to "render those pages".

I wrote this to give you some context.

Moreover, my app uses many third-party components, including DevExpress, ReportBuilder, SDAC Devart, and many others. As a consequence, the exe size without CEF4D is about 150MB.
With CEF4 the size is almost 250MB.

Somehow it works: I am able to see web pages in my application, even if I am still experimenting to see how CEF4Delphi works and I am far from the desired result, but I hope to succeed in the end.

I am a bit worried about the stability so I would like to ask you about how safe it is to include CEF4D in an app like the one I described. By safe I mean safe from the exe stability point of view and overall convenience.

I noticed some out-of-memory errors when the users were running my exe for hours, initially, I was calling CreateGlobalCEFApp at the app initialization, now to try to understand those errors I postponed the call to when I first need to display a web page in my app. This seems to have improved the situation, but I am far from being 100% sure.

Anyway, my goal here is not to discuss each small problem I encounter, but just to have an opinion from an expert about using CEF4D in my context: is it safe? Are there some rules? Which are the best practices?

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

Re: Risks of including CEF4Delphi in an existing project

Post by salvadordf »

Hi,

Yes. It's safe to use CEF4Delphi for a really long time but you need to check that every browser is closed correctly.

Your application seems to be similar to the TabbedBrowser2 demo. Use its code in your application to create and destroy each tab dynamically.

You are already using a different EXE for the subprocesses but I'll say this for anyone else reading this thread :
It's highly recommended to use a different EXE for the CEF subproceses in applications using databases. See the SubProcess demo to know all the details.

If your application is 32 bits and the browsers can show any web content then add this code line to your DPR file :

Code: Select all

{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
CEF needs to set the LARGEADDRESSAWARE flag which allows 32-bit processes to use up to 3GB of RAM.
If you don't add this flag the rederer process will crash when you try to load large images.
However, if the browsers only show your content then you can omit that line but be sure to resize the large images.

You probably already know this but I'll say it in case others read this thread. "Out of memory" errors could also be caused by memory leaks that can be fixed using FastMM4.
https://github.com/pleriche/FastMM4
https://www.atozed.com/2021/07/detecting-memory-leaks-in-delphi-applications-using-fastmm-4/
thefunkyjoint
Posts: 513
Joined: Thu Aug 10, 2017 12:40 pm

Re: Risks of including CEF4Delphi in an existing project

Post by thefunkyjoint »

salvadordf wrote: Tue Nov 16, 2021 8:51 am You probably already know this but I'll say it in case others read this thread. "Out of memory" errors could also be caused by memory leaks that can be fixed using FastMM4.
https://github.com/pleriche/FastMM4
https://www.atozed.com/2021/07/detecting-memory-leaks-in-delphi-applications-using-fastmm-4/
Is it needed to use FastMM4 even in newer versions of Delphi ? I thought they fixed it in recent versions...
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Risks of including CEF4Delphi in an existing project

Post by salvadordf »

Yes, FastMM4 is included in the latest Delphi version but I still use the version from the original GitHub repository.

The FastMM version included in Delphi has some differences :
https://en.delphipraxis.net/topic/2370-difference-between-fastmm-4992-and-one-that-comes-with-delphi-103/
francesco.faleschini
Posts: 22
Joined: Tue Nov 09, 2021 9:08 am

Re: Risks of including CEF4Delphi in an existing project

Post by francesco.faleschini »

salvadordf wrote: Tue Nov 16, 2021 8:51 am Your application seems to be similar to the TabbedBrowser2 demo. Use its code in your application to create and destroy each tab dynamically.
Thanks a lot for the reply!
I compared the sample with my implementation. The main difference is that i use a dedicated exe for the browser subprocess.

I will create a dummy application that mimicks my real application and submit it to you so you can help me identify the approach.

My main concern is: add a so new layer as CEF4Delphi in an old (even it maintained and somehow modernized) app is somehow a big thing, I would like to be 100% sure things are done as per the best practices before releasing.

For this I will make a new thread in the next days.

About the memory problem: I know FastMM4 and I also think it has been incorporated in a not so recent Delphi version, at the times of Delphi 7 it was a must, now it is optional i think, but I may be wrong, of course.

Thanks a lot!
Post Reply