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.

Chromium in Multithread do not work

Post Reply
User avatar
Uefi1
Posts: 43
Joined: Tue Aug 24, 2021 1:58 pm

Chromium in Multithread do not work

Post by Uefi1 »

Hello, I don't understand why the browser doesn't work in a multi-threaded application =(

Code: Select all


type  th = class(TThread)
private
chrom:TChromium;
protected
  procedure Execute; Override;
 public
 procedure Chromium1LoadEnd(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame;
  httpStatusCode: Integer);
 
procedure th.Chromium1LoadEnd(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame;
  httpStatusCode: Integer);
begin
if (frame <> nil) and (frame.IsMain) and (httpstatuscode=200) then begin
form1.memo1.lines.add('WORK NOW DESTROYING>>');
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
chrom.CloseBrowser(false);
chrom.CloseBrowser(true);
chrom.CloseAllBrowsers;
PostMessage(chrom.BrowserHandle, CEF_DESTROY, 0, 0);
PostMessage(Handle, CEF_DESTROY, 0, 0);
PostMessage(Self.Handle, CEF_DESTROY, 0, 0);
PostMessage(Handle, WM_QUIT, 0, 0);
PostMessage(Self.Handle, WM_QUIT, 0, 0);
PostMessage(Handle, WM_CLOSE, 0, 0);
PostMessage(Self.Handle, WM_CLOSE, 0, 0);
chrom.CloseAllBrowsers;
chrom := nil;
Freeandnil(chrom);
chrom.free;
end;
end;
 
procedure th.Execute;
begin
inherited;
while work do begin
...
if work then begin
chrom:=TChromium.Create(nil);
chrom.OnLoadEnd:=Chromium1LoadEnd;
chrom.DefaultUrl:='https://';
if not chrom.Initialized then chrom.CreateBrowser(nil,'');
if chrom.Initialized=false then
chrom.Initialized
end;
end;
end;
The error in the decompiler explicitly points to this line:

Code: Select all

uCEFChromiumCore

{$IFDEF MSWINDOWS}
procedure TChromiumCore.CreateWindowWithWndProc;
begin
  if (Owner = nil) or not(csDesigning in ComponentState) then
    FCompHandle := AllocateHWnd({$IFDEF FPC}@{$ENDIF}WndProc);
end;
{$ENDIF}
Post Reply