Foreword
January 29th, 2010
This very short tutorial shows you how to add a progressbar to any webbrowser programs you make in less than 2 minutes. It is very basic and kept as short as possible. You can figure out most of the code just by looking at it. Aimed at beginners, this gives you an easy and quick way to have a working progressbar which informs the user of the progress the webbrowser is making! You can then focus on the other tasks like for instance the graphical representation to make it the way you want it. Included is the completed example.
I hope this little bit of conceptual knowledge will help you.
I like to hear your opinion, comments, problems you may have while using this helpfile, this goes for all of my published stuff, please email me I would very much appreciate it. Regards, Nullified Let's get going, you will be done in 2 minutes!
1. Start a new project
2. Drop a TWebBrowser component
3. Drop a TEdit component, In the object inspector change its Text property in:
h t t p : / / w w w . g o o g l e . n l
4. Drop a TButton component, doubleclick it and add:
FDownCount:=0; WebBrowser1.Navigate(Edit1.Text);
5. Drop a TProgressBar
6. In the private section add:
FDownCount: Integer;
7. Select the Webbrowser component, and go to the property inspector and click the tab events Doubleclick OnDownloadBegin [in the dropdownbox] add:
Inc(FDownCount); ProgressBar1.Position:=0;
Doubleclick OnDownloadComplete [in the dropdownbox] add:
Dec(FDownCount); ProgressBar1.Position:=0;
Doubleclick OnProgressChange [in the dropdownbox] add:
if (ProgressMax > 0) and (Progress > 0) and (FDownCount > 0) then begin ProgressBar1.Position:=Trunc(Progress / ProgressMax) * 100; ProgressBar1.Update; Sleep(100); Application.ProcessMessages; end;
8. You are finished now!
For your reference see the below Unit1.pas after it is finished:
//////////////////////////////////////////////////////////////////////////////////////// unit Unit1; //////////////////////////////////////////////////////////////////////////////////////// interface //////////////////////////////////////////////////////////////////////////////////////// uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls, OleCtrls, SHDocVw; //////////////////////////////////////////////////////////////////////////////////////// type TForm1 = class(TForm) Edit1: TEdit; ProgressBar1: TProgressBar; Button1: TButton; WebBrowser1: TWebBrowser; procedure Button1Click(Sender: TObject); procedure Webbrowser1DownloadBegin(Sender: TObject); procedure Webbrowser1DownloadComplete(Sender: TObject); procedure Webbrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer); private FDownCount: Integer; public { Public declarations } end; //////////////////////////////////////////////////////////////////////////////////////// var Form1: TForm1; //////////////////////////////////////////////////////////////////////////////////////// implementation {$R *.dfm} //////////////////////////////////////////////////////////////////////////////////////// procedure TForm1.Button1Click(Sender: TObject); begin FDownCount := 0; WebBrowser1.Navigate(Edit1.Text); end; //////////////////////////////////////////////////////////////////////////////////////// procedure TForm1.Webbrowser1DownloadBegin(Sender: TObject); begin Inc(FDownCount); ProgressBar1.Position := 0; end; //////////////////////////////////////////////////////////////////////////////////////// procedure TForm1.Webbrowser1DownloadComplete(Sender: TObject); begin Dec(FDownCount); ProgressBar1.Position := 0; end; //////////////////////////////////////////////////////////////////////////////////////// procedure TForm1.Webbrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer); begin if (ProgressMax > 0) and (Progress > 0) and (FDownCount > 0) then begin ProgressBar1.Position := Trunc(Progress / ProgressMax) * 100; ProgressBar1.Update; Sleep(100); Application.ProcessMessages; end; end; //////////////////////////////////////////////////////////////////////////////////////// end. ////////////////////////////////////////////////////////////////////////////////////////