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.

Debugging Problems and strange behavior

User avatar
Minz3
Posts: 17
Joined: Tue Nov 12, 2019 12:55 pm

Re: Debugging Problems and strange behavior

Post by Minz3 »

Hey,

again thank you for your patience! At least I have a whtie window now (it kept gray before). So after the initialization I immediately create the child form like that.

Code: Select all

procedure TPWAModuleForm.FormShow(Sender: TObject);
begin
  if (GlobalCEFApp <> nil) and GlobalCEFApp.GlobalContextInitialized then
    begin
      Caption            := 'ToolBox Browser';
      cursor             := crDefault;
      CreateToolboxChild('ToolBox Browser', 'http://www.google.de');
    end
  else
    ShowMessage('CEF App is not initialized');
end;
I thought that would be ok too, when I dont need an addressbar and go button because I would only visit one site.

But it does not open the url properly. As I said it only shows a white screen:
Image

Also after I clicked the closing button the CloseQuery function will be executed and FClosing will be set to true but the windows keeps open.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Debugging Problems and strange behavior

Post by salvadordf »

It looks like the TChromium browser in the child form is not created.

Please try this and post the results :
  • Build the ToolBoxBrowser demo without modifications and try to open http://www.google.de. If it doesn't open that website check if you have any proxy in your local network. Perhaps the antivirus is blocking Internet access to some applications.
  • Set a breakpoint in your application at the line with the Chromium1.CreateBrowser call inside the TChildForm.FormShow procedure. This code line should be executed and it should return TRUE.
User avatar
Minz3
Posts: 17
Joined: Tue Nov 12, 2019 12:55 pm

Re: Debugging Problems and strange behavior

Post by Minz3 »

The Demo works fine and Chromium1.CreateBrowser returns TRUE.

Edit:
Because of Debugging problems I checked it like this:

Code: Select all

procedure TChildForm.FormShow(Sender: TObject);
begin
  if Chromium1.CreateBrowser(CEFWindowParent1, '') then
    ShowMessage('True')
  else
    ShowMessage('False');
end;
Edit:
BrowserCreatedMsg never gets called.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Debugging Problems and strange behavior

Post by salvadordf »

Please, set a breakpoint in these procedures to see if they are executed :
  • TChildForm.Chromium1AfterCreated
  • TChildForm.BrowserCreatedMsg
Use the same CEF binaries you had when you tested the ToolBoxBrowser demo.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Debugging Problems and strange behavior

Post by salvadordf »

I see you edited your message while I was writing mine :P

Please, check that TChildForm.Chromium1AfterCreated is executed and the CEFBROWSER_CREATED message is sent to the child form.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Debugging Problems and strange behavior

Post by salvadordf »

If you always open the same website you can also set TChromium.DefaultURL before calling TChromium.CreateBrowser to load it automatically as soon as the browser is created.
User avatar
Minz3
Posts: 17
Joined: Tue Nov 12, 2019 12:55 pm

Re: Debugging Problems and strange behavior

Post by Minz3 »

Both, TChildForm.Chromium1AfterCreated & TChildForm.BrowserCreatedMsg are not getting executed. But CreateBrowser returns true... strange.

I can just estimate that CEFBROWSER_CREATED is send to the child form because somehow I can't debug the CEF components. Even if I try to jump from other, which are calling the CEF forms into it.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Debugging Problems and strange behavior

Post by salvadordf »

Strange indeed...

Please check that :
  • The CEF binaries were extracted from the "Release" and "Resources" directories. The binaries in the "Debug" directory are a known cause of unexpected issues.
  • The GlobalCEFApp properties are the same for the main application EXE and the subprocess, specially the FrameworkDirPath, ResourcesDirPath, LocalesDirPath, cache and UserDataPath paths. The GlobalCEFApp.BrowserSubprocessPath property should only be set in the main application.
  • The Subprocess.exe file from the SubProcess demo is loaded by mistake in your application instead of the right subprocess.exe. They could have different GlobalCEFApp properties and cause these problems.
User avatar
Minz3
Posts: 17
Joined: Tue Nov 12, 2019 12:55 pm

Re: Debugging Problems and strange behavior

Post by Minz3 »

The CEF binaries were extracted from the "Release" and "Resources" directories. The binaries in the "Debug" directory are a known cause of unexpected issues.
I rebuild the ToolBoxBrowser Demo and put the output into the main project.
The GlobalCEFApp properties are the same for the main application EXE and the subprocess, specially the FrameworkDirPath, ResourcesDirPath, LocalesDirPath, cache and UserDataPath paths. The GlobalCEFApp.BrowserSubprocessPath property should only be set in the main application.
I never changed the default properties of the GlobalCEFApp. The only thing I have changed is at the uCEFLoader.pas

Code: Select all

  GlobalCEFApp.BrowserSubprocessPath := ExtractFilePath(Application.ExeName) + 'ERPSubProcess.exe';
What are the default paths? And I thought because of the SubProcess I just need to implement the uCEFLoder instead of changing the MainApp.dpr, am I right or did I get something wrong? The SubProcess.dpr is also untouched.

Code: Select all

program SubProcess;

{$I cef.inc}

uses
  {$IFDEF DELPHI16_UP}
  WinApi.Windows,
  {$ELSE}
  Windows,
  {$ENDIF}
  uCEFApplication;

{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}

begin
  GlobalCEFApp                  := TCefApplication.Create;
{
  GlobalCEFApp.FrameworkDirPath     := 'cef';
  GlobalCEFApp.ResourcesDirPath     := 'cef';
  GlobalCEFApp.LocalesDirPath       := 'cef\locales';
  GlobalCEFApp.cache                := 'cef\cache';
  GlobalCEFApp.UserDataPath         := 'cef\User Data';
}

  GlobalCEFApp.StartSubProcess;
  GlobalCEFApp.Free;
  GlobalCEFApp := nil;
end.
The Subprocess.exe file from the ToolBoxBrowser demo is loaded by mistake in your application instead of the right subprocess.exe. They could have different GlobalCEFApp properties and cause these problems.
Where could I check if the right EXE was loaded? Can I force to build it, when compiling? Because I just copied the subprocess.exe from the demo and changed the name. In the Task Manager I see the right Subprocess with the correct name.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Debugging Problems and strange behavior

Post by salvadordf »

I just uploaded a new demo called "ToolBoxSubProcessBrowser" to GitHub.

It uses a different EXE for the subprocesses that you need to build using the ToolBoxSubProcessBrowser_sp.dproj file.
Then build the ToolBoxSubProcessBrowser.dproj file and run ToolBoxSubProcessBrowser.

When you run it you will see one ToolBoxSubProcessBrowser.exe process and a few ToolBoxSubProcessBrowser_sp.exe processes.

The CEF initialization has been modified to use a simple timer like the rest of the demos. The TMainForm.CheckCEFInitialization procedure enables the user interface in the main form if CEF is fully initialized or enables a timer to check again after 1 second.

The child form has a slightly modified TChildForm.FormCloseQuery procedure and it shouldn't have problems closing it even when the browser has failed for some reason.

The main DPR file (ToolBoxSubProcessBrowser.dpr) only needed adding the IMAGE_FILE_LARGE_ADDRESS_AWARE flag and the "Windows" unit. The rest is a normal autogenerated DPR file.

Remeber that if you modify any GlobalCEFApp property in uCEFLoader.pas you will also need to modify those properties in the ToolBoxSubProcessBrowser_sp.dpr file.

If you use the latest CEF release instead of the main GitHub branch you will need to make a couple of changes in ToolBoxSubProcessBrowser_sp.dpr
  • Replace "uCEFApplicationCore" with "uCEFApplication" in the uses section.
  • Replace "GlobalCEFApp := TCefApplicationCore.Create;" with "GlobalCEFApp := TCefApplication.Create;" in the code.
Post Reply