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.

how to stop and exit the demo of cef4

Post Reply
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how to stop and exit the demo of cef4

Post by salvadordf »

You need to close all browser tabs before closing your application as you can see in the TMainForm.FormCloseQuery procedure.

Set FClosing to TRUE and call the "CloseAllBrowsers" function.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how to stop and exit the demo of cef4

Post by salvadordf »

CEF3 requires to follow some steps to close the browsers safely. I usually call that procedure "the destruction sequence" and it's used in all the demos.

The demos have some code comments in the beginning of the unit with all the details. In the case of the TabbedBrowser demo it's here :
https://github.com/salvadordf/CEF4Delph ... m.pas#L144

Code: Select all

// 1. FormCloseQuery hides the form and calls CloseAllBrowsers which calls TChromium.CloseBrowser in all tabs and triggers the TChromium.OnClose event.
// 2. TChromium.OnClose sends a CEFBROWSER_DESTROYWNDPARENT message to destroy TCEFWindowParent in the main thread which triggers a TChromium.OnBeforeClose event.
// 3. TChromium.OnBeforeClose sends a CEFBROWSER_CHECKTAGGEDTABS message to set the TAG property to 1 in the TabSheet containing the TChromium. Then sends WM_CLOSE in case all tabsheets have a TAG = 1.
To close that demo you can do what I commented previously about setting FClosing and calling CloseAllBrowsers, but you can also send a WM_CLOSE to the main form.

If your app doesn't create a tab initially you will also have to modify the BrowserCheckTaggedTabsMsg procedure to set FCanClose to TRUE and send WM_CLOSE to close the app when there are no tabs.
Post Reply