Page 1 of 1

TIdHTTP freeze on CEF4Old work

Posted: Sat Jul 07, 2018 1:30 pm
by RedOctober
Hello! Please take a look to this code:

Code: Select all

procedure TMainFrom.IdHTTP_updateWork(ASender: TObject;
  AWorkMode: TWorkMode; AWorkCount: Int64);
  var download_percent:integer;
begin
  download_percent:=round(AWorkCount * 100 / update_file_size);
  Chromium1.browser.MainFrame.ExecuteJavaScript
  ('$(".progress").progress({percent: '+inttostr(download_percent)+'});',
  'about:blank', 0);
end;
The idea is to use JavaScript to show the progress of file download on the page loaded in Chromium. Everything works fine, but Chromium freezes while file is loaded, and only draws progress after the download is complete. Is there any analogue of Application.ProcessMessages for Chromium?

Re: TIdHTTP freeze on CEF4Old work

Posted: Sat Jul 07, 2018 2:17 pm
by salvadordf
The answer from Remy Lebeau in stackoverflow is the best way to use TIdHTTP without blocking the user interface.
https://stackoverflow.com/questions/512 ... n-cef-work

Create a thread and use TIdHTTP in that thread. In addition to that I would also suggest that you only update the progress bar once every second or 500ms.

Re: TIdHTTP freeze on CEF4Old work

Posted: Sat Jul 07, 2018 2:29 pm
by salvadordf
TChromium can also be used to download files with TChromium.StartDownload and it will download the file in the background without blocking the user interface.

The MiniBrowser demo has all the code to download files. It uses the TChromium.OnDownloadUpdated event to show the download progress information in the status bar.

Re: TIdHTTP freeze on CEF4Old work

Posted: Sat Jul 07, 2018 9:12 pm
by RedOctober
Hi Salvador,

yes, threads is not suits me, but OnDownloadUpdated is pretty fine to me. Thank you!