best way to implement a download manager: extension

This is a question for TheRealLoki and is a reference to:

Can you please post the extended code example you mentioned in your previous answer?
Who is Participating?
TheRealLokiConnect With a Mentor Senior DeveloperCommented:
I've made a Delphi 7 Indy 9 version. Will start on an indy 10 version later.
I haven't finished the "highlighting" in the TListView, but that's just cosmetic, and not necessary for the basic design.
You can easily adapt it to show the updates (% downloaded) in a grid on another form.

If you get a zero length .zip when you download the demo, just wait and try again. It can take a few mins for sourceforge to get the package out to all its' mirrors.
hibbidijiAuthor Commented:
What I need to implement will ne in a new window and will use a gridview for it's display.  I will be calling these objects from my main form.
I also look forward to seeing the extended code, TheRealLoki answered my questions about Threads the other day and I found his code to be excellent, I read the previous question (in your question) and again his code is really nice to read.... learning alot from you TheRealLoki  =) keep up the good work.
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

hibbidijiAuthor Commented:
I'm glad to see that these questions are helping other people - I always worry that I'm too specific :)
TheRealLokiSenior DeveloperCommented:
oh, for later versions, check the main page directly
Hey there,

Thanks for this, however I goto download it and it says invalid archive (16.6k big)
tired all the mirrors and get the same on all of them...  Will try again in 15 but just a heads up.
hibbidijiAuthor Commented:
I downloaded and opened the project in D2005 with Indy9.    On opening the project for the first time I got a couple messages about properties that did not exist for the client - these did not return (for me to report to you) on any subsequent open.    When attempting to compile, I get the following errors:

[Error] MultiFileDownloaderMain.pas(235): E2009 Incompatible types: 'Parameter lists differ'
[Error] MultiFileDownloaderMain.pas(236): E2009 Incompatible types: 'Parameter lists differ'
[Fatal Error] MultiFileDownloader.dpr(5): F2063 Could not compile used unit 'MultiFileDownloaderMain.pas'

It seems that trying to open the zip file with winzip gives that error, however winrar was OK.
I compiled the source ok and only got a res file error when opening first time (no issue though).

TheRealLokiSenior DeveloperCommented:
you are not using Indy 9
you are most likely using indy 10, that is why I have the demos in specific releases, 1 for each environment I actually own.
so, "Indy 9 Delphi 7" and "Indy 10 Delphi 5"
I have just made an Indy 10 demo also
goto the main site, and click on download for the appropriate version you have
TheRealLokiSenior DeveloperCommented:
hmmm, maybe i should start zipping these up with an older pkzip just to be compatible with everyone. I use WinRar 8 for most things
hibbidijiAuthor Commented:
My errors even with package titled:  
hibbidijiAuthor Commented:
I take it back - I DID get an error when opening the indy10 packaged app but it compiled fine and runs like a champ :)
Fantastic work as usual - now I just need to read it enough times to understand it.   Kudos.
hibbidijiAuthor Commented:
If you are still watching this question, I would like to add pause and cancel functionality as well as cancel all downloads.    I'm happy to open a new question but I would appreciate assistance if you see this.
A good way to learn is first write down on paper how you think it would work in just enlish
get thread name
pause/stop thread
display this to user

or something
then from there look at writing the code as to how you think it would work, and then post here
just a suggestion =)
TheRealLokiSenior DeveloperCommented:
You cannot just "pause", so I'm guessing you mean, stop, but allow this to be continued  (resumed) later.
note: not all servers support "resuming"

to "cancel" - all you need to do, is terminate the thread, and have the indy IdHTTP component stop somehow.
1 way to do this is raise an exception in the IdHTTP.OnWOrk event.
eg. in the IdHTTP.OnWork have some code like
if terminated then raise EUserAskedMeToCancel.create('cancelling.') else....
( declared as:  type EUserAskedMeToCancel = class Exception; // made my own exception to show cancelling )
This unfortunately means you will have to keep track of the thread
ie. instead of just
you will need to have
IndyInAThread: TIndyInAThread;
IndyInAThread := TIndyInAThread.Create(...
so that you can just say "IndyInAThread.Terminate;" to cancel.
perhaps put this in a "StopDownload" procedure of TDownloadableFile

so to stop all, you would do

        i: integer;
        for i := 0 to pred(DownloadableFileList.Count) do

Info I'm sure you'll want later...
To have Indy "resume" a download from a specifed point, you set the
Request.ContentRangeStart and Request.ContentRangeEnd values before you perform the GET()
It is possible to have 5 threads (for example) grabbing different parts of the same file. This is a common method to improve download speeds where servers throttle each connection. you have 5 connections, so you get the file faster. (assuming you have an internet connection faster than the server's "throttled" limit for each connection)
Note: some servers have caught on to this, and only allow 1 or 2 connections per IP adddress

Let me know if you want me to do a proper demo for you on this, but I know the above works
hibbidijiAuthor Commented:
In the interest of making sure this is done right, I've opened a new question. it is here:

Your work is excellent and I hope you will be able to update your demo with this new functionality (just cancellation, not pause / resume)
I am working in d2005 with indy10

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.