IEDownload

Getting started

 


IEDownload has only four main procedure:

procedure Go(Url: string); overload;
procedure Go(Url, Fname: string); overload;
procedure Cancel(Item: TBSCB); overload;
procedure Cancel; overload;


To start download you just say:

IEDownload1.Go(Url);

and to abort the download:

IEDownload1.Cancel;


In the following code 3 urls are downloaded. 

If Asynchronous and AsyncStorage are selcted in Options IEDownload will download them asynchronous (non-blocking). They will all be downloaded simultaneously, and you don't know which one will finish first. 

If you choose to download synchronous (Asynchronous disabled in Options) IEDownload wil start downloading the first URL and finish it before downloading the next.

In this code a memo field display the data as they arrive:


var

Links : TStringlist;

procedure
TForm1.Button1Click(Sender: TObject);
var
x : integer;
begin
Links:=TStringlist.create;
Links.add('http://www.borland.com');
Links.add('http://www.inprise.com');
Links.add('http://www.microsoft.com');
For x:=0 to Links.count-1 do IEdownload1.Go(Links[x]);
end;

procedure TForm1.IEDownload1Data(Sender: TBSCB; var Buffer: PByte;
var BufLength: Cardinal);
begin
memo1.lines.add(Pchar(Buffer));
end;

If they are downloaded synchronous the memo will display the source from the first URL then continue with the source from the next.

If downloaded asynchronous the source will be completely mixed up, depending on what server is fast enought to deliver some data.

To keep track of what data belongs to what URL you need to use the Sender parameter, which is available in all eventhandlers. 

Sender.Url contains the url to which the data belong.

So if you want to download the 3 urls asynchronous and display the source in three different memoboxes the OnData code should be changes to the following:

procedure TForm1.IEDownload1Data(Sender: TBSCB; var Buffer: PByte;
var BufLength: Cardinal);
begin
case Links.IndexOf(Sender.Url) of
0: memo1.lines.add(PChar(Buffer));
1: memo2.lines.add(PChar(Buffer));
2: memo3.lines.add(PChar(Buffer));
end;
end;

You can always cancel the download of a specific URL by using IEDownload1.Cancel(Sender).

IEDownload1.Cancel  without any parameter will cancel all ongoing downloads.

If you want to add a progressbar to each of the three download, you will also have to use the Sender.URL:

function TForm1.IEDownload1Progress(Sender: TBSCB; ulProgress,
ulProgressMax, ulStatusCode: Cardinal; szStatusText: PWideChar): HRESULT;

begin

   case Links.IndexOf(Sender.Url) of
       0:
          begin
          progressbar1.Max := ulProgressMax;
          progressbar1.Position := ulProgress;
          end;
        1:
          begin
            
progressbar2.Max := ulProgressMax;
          progressbar2.Position := ulProgress;
          end;
        2:
          begin
           
progressbar3.Max := ulProgressMax;
          progressbar3.Position := ulProgress;
          end;
    end;
end;



You can use a few more methods in Sender:

Sender.QueryInfo
Sender.QueryOptions
Sender.GetBindResult

For information about the great amount of information you can get from these methods, see: 

IWinInetInfo--QueryOption Method
IWinInetHttpInfo--QueryInfo Method

IBinding--GetBindResult Method



Using Method Post and PostData:

The following code shows how to use the post method:

procedure TForm1.Button1Click(Sender: TObject);
begin
(*
Following line is default and not needed unless you
have changed AdditionalHeader
*)
IEDownload1.AdditionlaHeader.add(
'Content-Type: application/x-www-form-urlencoded');

IEDownload1.Method:=Post;
IEDownload1.PostData:='firstname=Per&lastname=Larsen';
IEDownload1.Go('http://localhost/postmon.asp');
end;


Created and maintained by
Per Lindsų Larsen

Last Update: October 1, 2000