?
Solved

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

Posted on 2006-07-13
9
Medium Priority
?
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 12

Accepted Solution

by:
AmigoJack earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

801 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