#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2007
    Posts
    34
    Rep Power
    7

    IdHTTP Progress?


    Hey.

    I'm using IdHTTP to download a file, just one simple file.

    IdHTTP1.Get('address/file.zip', myFileStream);

    That's the code I use. Downloading works just fine.

    I would like to implement a progressbar AND download speed, so that the user knows how fast the file is coming and how much left.

    Currently I use:

    ProgressBar1.Progress := myFileStream.Size;

    and

    ProgressBar1.Max := (HTTP response to Content-Length)

    Is this a good way, because this makes flicker and occasionally jumps real quick to 100% in ProgressBar and then back to what it really needs to be.

    In IdHTTP's onWork event I use Application.ProcessMessages and Sleep 10 milliseconds.

    I've also tried Gauge control.

    Any suggestions are a-OK.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Max progress


    Solution of MAX/POSITION for progressBar:

    Code:
    procedure TForm1.IdHTTPWorkBegin(ASender: TObject; AWorkMode: TWorkMode;
      AWorkCountMax: Int64);
    begin
      Screen.Cursor := crHourGlass;
      ProgressBar.Max := AWorkCountMax;
      ProgressBar.Position := 0;
    end;
    
    procedure TForm1.IdHTTPWork(ASender: TObject; AWorkMode: TWorkMode;
      AWorkCount: Int64);
    begin
      ProgressBar.Position := AWorkCount;
    end;
    
    
    procedure TForm1.IdHTTPWorkEnd(ASender: TObject; AWorkMode: TWorkMode);
    begin
      Screen.Cursor := crDefault;
    end;
    is it enough? Average speed you can calculate from AWorkCount ;-)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    I get this error

    [dcc32 Error] project.pas(949): E2009 Incompatible types: 'Parameter lists differ'
    when I try to call WorkBegin and Work

    procedure Tform2.DownloadTable;

    var
    ms: TMemoryStream;
    path :string;

    begin

    ms := TMemoryStream.Create;
    path := DIR; //global variable

    try
    with IdHttp1 do
    IdHTTP1.Get(URLTAB, ms);
    ms.Position := 0;
    SetCurrentDir(path);
    ms.SaveToFile('table.rar');
    IdHttp1.OnWorkBegin := WorkBegin;
    IdHttp1.OnWork := Work;

    finally
    ms.Free;

    end;
    end;

    procedure TForm2.WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
    const AWorkCountMax: Int64);
    begin
    ProgressBar2.Max := AWorkCountMax;
    end;

    procedure TForm2.Work(ASender: TObject; AWorkMode: TWorkMode;
    const AWorkCount: Int64);
    begin
    ProgressBar2.Position := AWorkCount;
    end;


    Maybe I found the errors. The exact code should be:

    procedure Tform2.DownloadTable;

    var
    ms: TMemoryStream;
    path :string;

    begin

    ms := TMemoryStream.Create;
    path := DIR; //global variable

    try
    with IdHttp1 do
    begin
    Get(URLTAB, ms);
    ms.Position := 0;
    SetCurrentDir(path);
    ms.SaveToFile('table.rar');
    OnWorkBegin := WorkBegin;
    OnWork := Work;
    end;

    finally
    ms.Free;

    end;
    end;

    procedure TForm2.WorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64);
    begin
    ProgressBar2.Max := AWorkCountMax;
    end;

    procedure TForm2.Work(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
    begin
    ProgressBar2.Position := AWorkCount;
    end;

    I can compile the exe but I stil have a problem: I can see download progress only the second time i push on the button.
    Last edited by ASAP; October 19th, 2012 at 01:07 PM. Reason: maybe I found the solution

IMN logo majestic logo threadwatch logo seochat tools logo