Docstoc

Delphi Internet Programming

Document Sample
Delphi Internet Programming Powered By Docstoc
					  Download Files in Internet Using Progress Bar In Delphi
If we want to download a file on the Internet using a URL address using a progress bar as
an indicator of processing, you can menggunakn TDownloadURL at Delphi has been
provided on ExtActns Unit.

His work system as follows: When we TDownloadURL make the download process,
periodically the system will display the total number of Bytes that are downloaded along
with the number of Bytes that have been downloaded. Well, from the system, we can use
it on the progress bar, so the program look more attractive.

Here is an example program:

1. Create a new project with a name and save Downloader

2. FrMain named on the form, add a Button component named button1, and ProgressBar
ProgressBar1 name

3. Add the following code (in bold)

/ / Call the unit ExtActns

ExtActns uses, …

type
TfrMain = class (TForm)
…
private

/ / Create a procedure for use on the progress bar
URL_OnDownloadProgress procedure
(Sender: TDownLoadURL;
Progress, ProgressMax: Cardinal;
StatusCode: TURLDownloadStatus;
StatusText: String; var Cancel: Boolean);
…

implementation
…

4. Add the following functions:

/ / Update progress bar

TfrMain.URL_OnDownloadProgress procedure;
begin
ProgressBar1.Max: = ProgressMax;
ProgressBar1.Position: = Progress;
end;

/ / Dwonload file

DoDownload function;
begin
with TDownloadURL.Create (self) do
try

/ / You can change the address to be appropriate desideratum dg

URL: = ‘http://software-files-
l.cnet.com/s/software/11/11/80/47/objectdock_freeware.exe?e=1267635908&h=716641d
fbba6242b137cdc7a5329058c&lop=link&ptype=1901&ontid=2072&siteId=4&edId=3&
spi = 032363f41f5343115c37e68f13f70633 & pid = 11118047 & psid = 10210264 &
filename = objectdock_freeware.exe ‘;
Filename: = ‘c: \ objectdock_freeware.exe’;
OnDownloadProgress: = URL_OnDownloadProgress;

ExecuteTarget (nil);
Finally
Free;
end;
end;

5. Add onclick event on button1 as follows:

TfrMain.Button1Click procedure (Sender: TObject)
begin
DoDownload;
end;

6. Press F9 and then do click on the button and note the progress that occurred in the
Progress Bar,

Congratulations you have successfully created a downloader program, with a little
creativity, you can develop them into a program that is more reliable ..

Good luck …

Regards

Andri

				
DOCUMENT INFO
Description: Delphi Internet Programming