Solved

Graphical [not a textual] progressbar for my webbrowser program [1000 points reward]

Posted on 2006-07-13
9
332 Views
Last Modified: 2010-04-05
Hi all

I managed to get a textual indicator of the progress into my program but did not manage to get the visual progressbar working, anyone who can help me get a progressbar to work, will receive 1000 points, since I really have searched this place and the helpfiles but cannot get it to work, here is the code:
===========================
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, SHDocVw, IEClasses, AwayTimer, Menus, ComCtrls;

type
  TForm1 = class(TForm)
    wb1: TWebBrowser;
    btn1: TButton;
    btn2: TButton;
    btn3: TButton;
    btn4: TButton;
    btn5: TButton;
    btn6: TButton;
    edt1: TEdit;
    edt2: TEdit;
    edt3: TEdit;
    lbl1: TLabel;
    lbl2: TLabel;
    pbPbr1: TProgressBar;
    btn7: TButton;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure btn3Click(Sender: TObject);
    procedure btn4Click(Sender: TObject);
    procedure btn5Click(Sender: TObject);
    procedure btn6Click(Sender: TObject);
   
    procedure wb1DownloadBegin(Sender: TObject);
    procedure wb1DownloadComplete(Sender: TObject);
    procedure wb1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer);
    procedure btn7Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
begin

wb1.Navigate('http://');
end;

procedure TForm1.btn2Click(Sender: TObject);
begin

wb1.Navigate('http://');
end;

procedure TForm1.btn3Click(Sender: TObject);
begin
wb1.Navigate('http://');
end;

procedure TForm1.btn4Click(Sender: TObject);
begin
wb1.Navigate('http://');
end;

procedure TForm1.btn5Click(Sender: TObject);
begin
wb1.Navigate('http://');
end;

procedure TForm1.btn6Click(Sender: TObject);
begin
wb1.Navigate('http://');
end;


procedure TForm1.wb1DownloadBegin(Sender: TObject);
begin
//pb1.Step:=5;
end;

procedure TForm1.wb1DownloadComplete(Sender: TObject);
begin
//pb1.Position:=100;
//pb1.Position:=0;
end;

procedure TForm1.wb1ProgressChange(Sender: TObject; Progress,
  ProgressMax: Integer);
begin
if ProgressMax = 0 then
  begin
   
    lbl1.Caption := '';
    Exit;
  end;
  try
    if (Progress <> -1) and (Progress <= ProgressMax) then
      lbl1.Caption := IntToStr((Progress * 100) div ProgressMax) + '% loaded...'
      else

           lbl1.Caption :='';
  except
    on EDivByZero do Exit;
  end;

end;

procedure TForm1.btn7Click(Sender: TObject);
begin
close;
end;

end.

===============

Anyone pls?
0
Comment
Question by:fdehell
  • 4
  • 4
9 Comments
 
LVL 12

Accepted Solution

by:
AmigoJack earned 500 total points
ID: 17099595
wheres the problem? change

lbl1.Caption := IntToStr((Progress * 100) div ProgressMax) + '% loaded...'

to

pb1.Position:= (Progress * 100) div ProgressMax;
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17099615
Example of handling progress for browser control. Source first then dfm so there is no confusion.

Russell

---


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OleCtrls, SHDocVw, ComCtrls;

type
  TForm1            =class(TForm)
     ProgressBar1:  TProgressBar;
     WebBrowser1:   TWebBrowser;
     Button1:       TButton;
     Edit1:         TEdit;
     procedure      WebBrowser1DownloadBegin(Sender: TObject);
     procedure      WebBrowser1DownloadComplete(Sender: TObject);
     procedure      WebBrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer);
     procedure      Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WebBrowser1DownloadBegin(Sender: TObject);
begin
  ProgressBar1.Position:=0;
end;

procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
begin
  ProgressBar1.Position:=0;
end;

procedure TForm1.WebBrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer);
begin
  if (ProgressMax > 0) and (Progress > 0) then
  begin
     ProgressBar1.Position:=Trunc(Progress / ProgressMax) * 100;
     ProgressBar1.Update;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  WebBrowser1.Navigate(Edit1.Text);
end;

end.

--- dfm ---

object Form1: TForm1
  Left = 287
  Top = 146
  Width = 793
  Height = 528
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ProgressBar1: TProgressBar
    Left = 8
    Top = 468
    Width = 765
    Height = 17
    Min = 0
    Max = 100
    TabOrder = 0
  end
  object WebBrowser1: TWebBrowser
    Left = 8
    Top = 40
    Width = 765
    Height = 417
    TabOrder = 1
    OnProgressChange = WebBrowser1ProgressChange
    OnDownloadBegin = WebBrowser1DownloadBegin
    OnDownloadComplete = WebBrowser1DownloadComplete
    ControlData = {
      4C000000114F0000192B00000000000000000000000000000000000000000000
      000000004C000000000000000000000001000000E0D057007335CF11AE690800
      2B2E126208000000000000004C0000000114020000000000C000000000000046
      8000000000000000000000000000000000000000000000000000000000000000
      00000000000000000100000000000000000000000000000000000000}
  end
  object Button1: TButton
    Left = 8
    Top = 12
    Width = 75
    Height = 21
    Caption = 'GO'
    TabOrder = 2
    OnClick = Button1Click
  end
  object Edit1: TEdit
    Left = 88
    Top = 12
    Width = 485
    Height = 21
    TabOrder = 3
    Text = 'http://www.google.com'
  end
end
0
 
LVL 1

Author Comment

by:fdehell
ID: 17099672
Youre fast, if i knew where or what the problem was, i would not have asked it ofcourse, i have one little question more, after it has loaded the page, can the progressbar then be reset to 0, after a few seconds?
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 26

Expert Comment

by:Russell Libby
ID: 17099723

This code slows it down a little bit so you can actually see the prog meter update. Also, I noticed that on some pages the ProgressChange gets fired AFTER the document complete, thus the code for checking for download count. The code also resets the meter in the download complete event.

Russell

type
  TForm1            =class(TForm)
     ProgressBar1:  TProgressBar;
     WebBrowser1:   TWebBrowser;
     Button1:       TButton;
     Edit1:         TEdit;
     procedure      WebBrowser1DownloadBegin(Sender: TObject);
     procedure      WebBrowser1DownloadComplete(Sender: TObject);
     procedure      WebBrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer);
     procedure      Button1Click(Sender: TObject);
  private
     // Private declarations
     FDownCount:    Integer;
  public
     // Public declarations

  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

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;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FDownCount:=0;
  WebBrowser1.Navigate(Edit1.Text);
end;
0
 
LVL 1

Author Comment

by:fdehell
ID: 17099885
Wow both answers, both solved my question, what is your recommended advice regarding the points, I would say split the 1000 in half? It is great by the way, that by reading and understanding your answers, I learn more than i could ever learn in the delphi help files, this counts for the both of you btw
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17099957
A split is fine..

Russell
0
 
LVL 1

Author Comment

by:fdehell
ID: 17101139
Ok thank you Russel, your second answer was built into my program, if you wish, your name will be mentioned, or your details, anything you would like to see back, [this counts for the previous project too, I got the DelexteExclude from Peterdeb, who is my brother, and who got it from you as he told me some time ago, give me an email or state it here and i will take care of it

Amigojack, i thank you very much, since you were first, i will accept your answer as the solution, and make a reference to a new topic, in which i will refer to this one, where i will give Russel the other half of the points after he replies, since both answers as mentioned, are 100% solutions to this one

Yesss thxxxx
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17101640
No need to "mention" my name anywhere, and say hi to your brother for me ;-)

Regards,
Russell
0
 
LVL 1

Author Comment

by:fdehell
ID: 17106787
Thanks heaps, you really make my days....
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question