Solved

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

Posted on 2006-07-13
9
326 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:fdehell
Comment Utility
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
Comment Utility
A split is fine..

Russell
0
 
LVL 1

Author Comment

by:fdehell
Comment Utility
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
Comment Utility
No need to "mention" my name anywhere, and say hi to your brother for me ;-)

Regards,
Russell
0
 
LVL 1

Author Comment

by:fdehell
Comment Utility
Thanks heaps, you really make my days....
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now