Recent

Author Topic: fphttpclient example downloading with progressbar on the main form.  (Read 951 times)

han

  • Full Member
  • ***
  • Posts: 102
Attached my fphttpclient example for downloading  files or webpages with a progressbar on the main form.

I could not find any example for downloading files with a progressbar except this one: https://forum.lazarus.freepascal.org/index.php/topic,55886.msg415662.html?PHPSESSID=cq11qlk65nsrfkm6km43hdn7a5#msg415662

but in above example the download progressbar is on a new popup form. My new example allows placing the download progressbar on the main form. The data is placed in a string but it works for both text and binary files.

If OpenSSL is installed or libraries are available in your project directory then HTTPS is supported.

Tested in Windows, Linux and macOS.

Any suggestion to improve the code?

Han

« Last Edit: May 29, 2024, 02:19:20 pm by han »

Thaddy

  • Hero Member
  • *****
  • Posts: 14850
  • Censorship about opinions does not belong here.
I would use either a statusbar or put it in the form's caption bar. But it is a good idea.
Remember the Medway disaster..

Leledumbo

  • Hero Member
  • *****
  • Posts: 8764
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: fphttpclient example downloading with progressbar on the main form.
« Reply #2 on: June 01, 2024, 07:45:08 pm »
Any suggestion to improve the code?
It looks a bit weird to me that the interface is implemented by the form. If I were you, I would just use fphttpclient in the form directly. That OnDataReceived can take a form's method instead, directly updating the progress bar in the form. Despite available, interface is not often used in Object Pascal. The event driven nature of FCL/LCL kinda makes it unnecessary, you just assign event to the corresponding handler instead.

Something as simple as the attached project.

 

TinyPortal © 2005-2018