Page 1 of 1

Programm terminates after TChromium.Destroy

Posted: Thu Sep 21, 2017 12:06 pm
by andreas michelberger
Hallo I get sometimes Exceptions (Programm terminates) after TChromium.Destroy
Reason: TCustomClientHandler fires Events to destoyed TChromium

I fixed it by:

TCustomClientHandler = class(TCefClientOwn)
public ...
procedure DisconnectEvents;

destructor TCustomClientHandler.Destroy;
begin
DisconnectEvents;
inherited Destroy;
end;

procedure TCustomClientHandler.DisconnectEvents;
begin
FLoadHandler := nil;
FFocusHandler := nil;
FContextMenuHandler := nil;
FDialogHandler := nil;
FKeyboardHandler := nil;
FDisplayHandler := nil;
FDownloadHandler := nil;
FGeolocationHandler := nil;
FJsDialogHandler := nil;
FLifeSpanHandler := nil;
FRequestHandler := nil;
FRenderHandler := nil;
FDragHandler := nil;
FFindHandler := nil;
FEvents := nil;
end;

destructor TChromium.Destroy;
begin ...
if assigned(FHandler) then
TVCLClientHandler(FHandler).DisconnectEvents;
FHandler := nil;

Is there a better way to resolve this?

Kindly regards
Andreas Michelberger

Re: Programm terminates after TChromium.Destroy

Posted: Thu Sep 21, 2017 12:23 pm
by salvadordf
That was caused by a recent change in CEF's destruction sequence.

I created this issue about it :
https://github.com/salvadordf/CEF4Delphi/issues/53

The ToolboxBrowser and MDIBrowser demos included the fix for that.

As you can see in those demos, you have to remove the manual destruction of the TChromium component from TChildForm.BrowserDestroyMsg
You should only destroy TCEFWindowParent manually in that event and let the other components be destroyed when the form is destroyed.