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.

When form was shut, it will bring out error.

Post Reply
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

When form was shut, it will bring out error.

Post by coater »

If I didn't use sleep(1000) in FormClose procedure. When form was shut, it will bring out 'violation error'.
// Destruction steps
// =================
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
// 2. TChromium.OnClose sends a CEFBROWSER_DESTROY message to destroy CEFWindowParent1 in the main thread, which triggers the TChromium.OnBeforeClose event.
// 3. TChromium.OnBeforeClose sets FCanClose := True and sends WM_CLOSE to the form.
procedure TIinformSearchFrm.FormCreate(Sender: TObject);
begin
FCanClose := False;
FClosing := False;
FVisitor := TCefFastCookieVisitor.Create(CookieVisitorProc)//获取cookies
end;


procedure TIinformSearchFrm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//showmessage('');
sleep(1000) ;
Action := caFree;
end;

procedure TIinformSearchFrm.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin

CanClose := FCanClose;
if not(FClosing) then
begin
FClosing := True;
Visible := False;
Chromium1.CloseBrowser(True);
end;
end;

procedure TIinformSearchFrm.Chromium1Close(Sender: TObject; const browser: ICefBrowser; var aAction: TCefCloseBrowserAction);
begin
if (browser <> nil) and (Chromium1.BrowserId = browser.Identifier) then
begin
PostMessage(Handle, CEF_DESTROY, 0, 0);
aAction := cbaDelay;
end;
end;



procedure TIinformSearchFrm.BrowserDestroyMsg(var aMessage : TMessage);
begin
CEFWindowParent1.Free;
end;


procedure TIinformSearchFrm.Chromium1BeforeClose(Sender: TObject;
const browser: ICefBrowser);
begin
if (Chromium1.BrowserId = 0) then // The main browser is being destroyed
begin
FCanClose := True;
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
end;
You do not have the required permissions to view the files attached to this post.
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: When form was shut, it will bring out error.

Post by coater »

demos also:
(debug-shutdown)
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: When form was shut, it will bring out error.

Post by salvadordf »

Are you using the official CEF binaries found in the RELEASE folder? The binaries from the DEBUG folder cause lots of unexpected exceptions.

Are you using the CEF binaries with proprietary codecs you built?
If so, could you test the official CEF binaries from Spotify?

What Windows and Delphi version do you have?

Are you using the latest CEF4Delphi version?
If so, please add this line before the GlobalCEFApp.StartMainProcess call in the DPR file :

Code: Select all

GlobalCEFApp.DisableFeatures := 'NetworkService';
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: When form was shut, it will bring out error.

Post by coater »

in simplebrowser2: if 'Chromium1.DefaultURL := AddressEdt.Text' was disabled, this will happen.
procedure TForm1.FormCreate(Sender: TObject);
begin
FCanClose := False;
FClosing := False;
//Chromium1.DefaultURL := AddressEdt.Text;
end;

I use cef lib (build by my self).
Same things happened when using Spotify lib.
win7,10.2 25.0.29899.2631delphi


GlobalCEFApp.DisableFeatures := 'NetworkService';
This line works!

What's this means?
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: When form was shut, it will bring out error.

Post by salvadordf »

coater wrote: Fri Jul 05, 2019 1:18 am GlobalCEFApp.DisableFeatures := 'NetworkService';
This line works!
What's this means?
The "Network Service" is a new Chromium feature that was enabled by default in the recent CEF versions but sometimes it needs to be disabled because it still has some unresolved issues.

Read this for more information :
https://www.briskbard.com/forum/viewtopic.php?f=8&t=807
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: When form was shut, it will bring out error.

Post by coater »

Thank you very much!
Post Reply