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.

TChromiumWindow onBeforeClose not firing

Post Reply
MrDark
Posts: 3
Joined: Fri Dec 15, 2017 5:07 pm

TChromiumWindow onBeforeClose not firing

Post by MrDark »

The recently added "onBeforeClose" event never fires using TChromiumWindow.

Tested using SimpleBrowser.

I was trying to create a multi-tab browser using TChromiumWindow. The needed event never fires so I can't free the browser object and close the window tab. Any ideas why?
User avatar
salvadordf
Posts: 4085
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromiumWindow onBeforeClose not firing

Post by salvadordf »

Hi,

The complete destruction sequence for TChromiumWindow is described in the code comments inside the SimpleExternalPumpBrowser demo :
https://github.com/salvadordf/CEF4Delph ... rowser.pas

Run that demo and use a breakpoint in ChromiumWindow1BeforeClose.
MrDark
Posts: 3
Joined: Fri Dec 15, 2017 5:07 pm

Re: TChromiumWindow onBeforeClose not firing

Post by MrDark »

I tried the breakpoint before and followed many guides on the destruction sequence. No positive results.
All using the SimpleBrowser.

FYI: I'm using the latest build CEF 3.3239.1723.g071d1c1 on Delphi 2006 (Yes, I know, but I love the old bcc)
User avatar
salvadordf
Posts: 4085
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromiumWindow onBeforeClose not firing

Post by salvadordf »

Hi,

The SimpleExternalPumpBrowser demo has a complete implementation of the destruction sequence for TChromiumWindow. Take its code as a reference for your application.

This is the destruction sequence implemented in that demo :
  • The FormCloseQuery event sets CanClose to False and calls TChromiumWindow.CloseBrowser, which triggers the TChromiumWindow.OnClose event.
  • The TChromiumWindow.OnClose event calls TChromiumWindow.DestroyChildWindow which triggers the TChromiumWindow.OnBeforeClose event.
  • TChromiumWindow.OnBeforeClose sets FCanClose to True and closes the form.
If you follow those steps and TChromiumWindow.DestroyChildWindow returns True in the second step, then TChromiumWindow.OnBeforeClose should be triggered.

TChromiumWindow is a special component that has a slightly different destruction sequence and it's meant for quick browser implementations.
If your application creates several browsers I would recommend you to use the usual TChromium + TCEFWindowParent combination.
Post Reply