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.

TIdHTTP freeze on CEF4Old work

Post Reply
User avatar
RedOctober
Posts: 8
Joined: Sat Jul 07, 2018 12:59 pm
Location: Montenegro
Contact:

TIdHTTP freeze on CEF4Old work

Post 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?
User avatar
salvadordf
Posts: 4074
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TIdHTTP freeze on CEF4Old work

Post 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.
User avatar
salvadordf
Posts: 4074
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TIdHTTP freeze on CEF4Old work

Post 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.
User avatar
RedOctober
Posts: 8
Joined: Sat Jul 07, 2018 12:59 pm
Location: Montenegro
Contact:

Re: TIdHTTP freeze on CEF4Old work

Post by RedOctober »

Hi Salvador,

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