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 can I create a Chromium browser on a form in an existing application.

Post Reply
homer
Posts: 3
Joined: Thu Jan 18, 2024 10:54 pm

How can I create a Chromium browser on a form in an existing application.

Post by homer »

I have an office automation application written in Delphi 2007. I am trying to replace an existing simple browser based on TWebBrowser with one using CEF4Delphi. I downloaded the CEF4Delphi components last week, so I'm pretty sure I've got the latest release (license.md is dated 1/10/2024).

I wanted the new browser to resemble the old one as much as possible, so I started with the D7 SimpleBrowser demo and added mostly cosmetic changes. Now it looks and behaves very much like the old TWebBrowser browser. It works perfectly as a stand-alone application both in the IDE and when I double-click the .exe. However, I'm having trouble making it work as a form within the main office automation app. This is my first attempt at doing anything with Chromium or CEF4Delphi, so there is a lot I don't understand, even after reading the documentation. I hope someone can point me in the right direction.

When I open the form in my main office automation app via ShowModal, the form displays as expected but the application hangs and does not respond to mouse or keyboard. It also does not navigate to the designated URL. It doesn't get as far as the procedure: ChromiumWindow1AfterCreate or ChromiumLoadingStateChange.

When running in the IDE, I must kill the application with a Program Reset (Ctrl-F2). When running outside of the IDE, it must be stopped using the Windows Task Manager. In either case, the form showing Chromium can be closed, but neither it nor the application responds to any other user input.

I have added the Source folder the to the Delphi Search Path, and have added all .PAK files to the application's folder. As far as I know, the only difference between the demo compile that works, and the one with the form in the main application is in the Demo Application's Source file, which doesn't exist in the main application. So the main difference that I can spot has to do with the missing following code:

Code: Select all

  
  GlobalCEFApp := TcefApplication.Create;
  if GlobalCEFApp.StartMainProcess then
    begin
      Application.Initialize;
      Application.HintHidePause := 3000; // 3 seconds
      Application.CreateForm(TfrmChromium, frmChromium);
      Application.Run;
    end;
  GlobalCEFApp.Free;
  GlobalCEFApp := nil;
Being a Chromium beginner, I may be wrong about this assumption. Can someone please tell me if this could be the problem, and if it is, how to accomplish the same when the browser is on a form in an application rather than running as a stand-alone application. If this isn't the problem, maybe someone can coach me a bit. If looking at my code would help, I'd be happy to provide a sample.
homer
Posts: 3
Joined: Thu Jan 18, 2024 10:54 pm

Re: How can I create a Chromium browser on a form in an existing application.

Post by homer »

I solved the problem by creating a separate EXE, and launching it from the main app. Not elegant, but it works.
Post Reply