HKProgressBar v1.5
 By Harry Kakoulidis 11/1999

kcm@mailbox.gr
http://kakoulidis.homepage.com

This is Freeware. Please copy the file unchanged. If you find bugs, have options etc, please send at my e-mail.

The use of this component is at your own risk.
I do not take any responsibility for any damages.

HKProgressbar is a completely different approach to long loops that you might do sometime. You set up the component and it starts your process in a different thread, so you can continue using your program if wanted. If you want, a progress bar is shown, optionally with a cancel button. This way you can implement with very little code secondary threads, that can handle a cancel from the user. Can adopt to every situation. You don't have to worry about opening and closing the progress form. Tested with Delphi 4. Source & Demo with EXE included.

For an example, see the demo.

Properties are
** Caption       : The caption of the progress form
** TextString    : A string in the progress form
** FormPosition  : Select where to show the progress form
** UpdateTImes   : Every how many times the progress form will be updated (In 100000+ loops its not a good idea (slow) to update a progress form 100000+ times). Set to 1 if the loop is small (1..100)
** CanCancel     : Will the form have a cancel button?
** WaitTillFinish: Should the program wait until the job finishes?
** ShowDialog    : Should there be a progress form?. If not the process is launced in a different thread, and WailTillFinish is ignored.
** InThread      : New in version 1.5. I Discovered that this is a great option for debugging purposes, and sometimes the only option (some non borland components glue windows when you launch a thread). So until you know that everything is OK set this to false. You'll see that even with this false, everything is pretty much the same... (The way this works looks like multitasking in Win 3.1, but very safe). Just dont forget to call Setposition in your loop, or everything will stop until the loop finishes)

Events:
*** OnProcessItem                  : Required. Here you put your code for the loop
*** OnEnd(canceled : boolean)     : Code for when the process ends. The canceled flag is true if the user pressed cancel.

OnEnd is called ALWAYS whenever your loop is over, even if you exit the procedure. It will have canceled=true only if the cancel button was pressed.


Important procedures that you call in run time

** Procedure StartProgress(NumKnown); overload;
You call this to start your process. Set NumKnown=false if you dont know how long you will take, like when searching for files.

*** Procedure SetPosition(DoneNum,FromNum : Integer);
In each of your loops, call this to update the bar, or text. The bar-text will actually not update unless UpdateTimes has gone by. 

*** function UserCanceled: boolean;
Exit your loop if this is true. This means that the user pressed cancel.


NOTE : This component can be added to a Datamodule too, so you can do your job from there.

IMPORTANT : Do not free the owning form/datamodule until the job has finished!!!