Solved

HTTP Get with progress meter (with Indy?)

Posted on 2009-05-06
3
811 Views
Last Modified: 2012-05-06
I'm looking for sample Delphi 7 code with Indy 9.0 that does an http get of a file, with a hook for an OnWork event (so I can have a progress meter.)

Does anyone know if this is possible with Indy. I'd prefer not to use another library if possible.
0
Comment
Question by:tfield98
[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
3 Comments
 
LVL 18

Accepted Solution

by:
Johnjces earned 500 total points
ID: 24320359
Try the following...

Not certain where I got the code.

John

drop a TIdHTTP, a TLabel a TIdAntiFreeze and a TProgressBar
 
procedure TForm1.IdHttp1WorkBegin(Sender:TObject; AWorkMode:TWorkMode;const AWorkCountMax:Integer);
begin
  if AWorkMode = wmRead then
  begin
    ProgressBar1.Max := AWorkCountMax ;
    ProgressBar1.Position := 0 ;
  end;
end;
 
procedure TForm1.IdHttp1Work(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer);
begin
  if AWorkMode = wmRead then
  begin
    ProgressBar1.Position := AWorkCount ;
    Label1.Caption := IntToStr(AWorkCount) + 'Bytes of :' + ProgressBar1.Max ;
  end;
end;
 
procedure TForm1.IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
  if AWorkMode = wmRead then
    Label1.Caption := 'Completed';
end;
 
to download,
 
var
  F: TFileStream;
begin
  F := TFileStream.Create('download.zip', fmCreate);
  try
    IdHTTP1.Get('http://somesite.com/downloads/download.zip', F);
  finally
    F.Free;
  end;
end;

Open in new window

0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24320457
Damn John, you beat me to it...
If you are using this for normal web page gets, you aren't going to see much progress as it will flash too fast.
0
 

Author Closing Comment

by:tfield98
ID: 31578764
The code worked perfectly (with an added IntToStr that was needed. Thanks A LOT, John!  (Yes, Eddie, I'm using it to download a large file, so it won't flash. But thanks for the heads up.)
0

Featured Post

Independent Software Vendors: 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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

726 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