DELPHI TDownLoadURL下载网络文件

unit Unit1; interface uses
//引用 Vcl.ExtActns
Vcl.ExtActns, System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, FMX.Edit; type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
ProgressBar1: TProgressBar;
Edit1: TEdit;
GroupBox2: TGroupBox;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure URL_OnDownloadProgress(Sender: TDownLoadURL;
Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus;
StatusText: String; var Cancel: Boolean); public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.fmx}
var
DownLoadURL1:TDownLoadURL; //url=网络文件 'http://helloroman.oicp.net:8000/test.rar';
//Filename=保存到本地文件 'D:\Administrator\Desktop\123.rar';
function DownLoadFile(url,Filename:string):boolean;
var
DownLoadURL1:TDownLoadURL;
begin
try
DownLoadURL1:=TDownLoadURL.Create(Form1);
DownLoadURL1.URL:= url;
DownLoadURL1.Filename:= Filename;
DownLoadURL1.OnDownloadProgress:=Form1.URL_OnDownloadProgress;
DownLoadURL1.ExecuteTarget(nil);
DownLoadURL1.Free;
Result:=true;
except
Result:=false;
end;
end; procedure DownLoadThread;
begin
Form1.label3.Text:='0 kb / 0 kb'; if DirectoryExists(ExtractFilePath(Form1.edit4.text)) then
begin
if not DownLoadFile(Form1.edit3.text,Form1.edit4.text) then
Form1.GroupBox1.Text:='下载失败'
else
Form1.GroupBox1.Text:='下载完毕';
end
else
SHowMessage(Form1.edit4.text + '不存在!'); end; procedure TForm1.Button1Click(Sender: TObject);
begin
TThread.CreateAnonymousThread(DownLoadThread).Start;
end; function BytesToStr(iBytes: Integer): String;
var
iKb: Integer;
begin
iKb := Round(iBytes / );
if iKb > then
Result := Format('%.2f MB', [iKb / ])
else
Result := Format('%d KB', [iKb]);
end; // 获取网络文件名
function GetUrlFileName(url:string):string;
var
str:string;
begin
url:=StringReplace(StrRScan(PChar(url),'/'), '/', '',[rfReplaceAll]);
if Pos('=',url) > then
url:=StringReplace(StrRScan(PChar(url),'='), '=', '',[rfReplaceAll]);
Result:=url;
end; procedure TForm1.URL_OnDownloadProgress(Sender: TDownLoadURL;
Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus;
StatusText: String; var Cancel: Boolean);
begin ProgressBar1.Max := ProgressMax div ;
ProgressBar1.Value := Progress div ; Caption := StatusText; case StatusCode of
dsFindingResource:GroupBox1.Text:='查找资源...';
dsConnecting:GroupBox1.Text:='连接中...';
dsRedirecting:GroupBox1.Text:='';
dsBeginDownloadData:GroupBox1.Text:='准备下载文件...';
dsDownloadingData:GroupBox1.Text:='下载中...'; end; Edit1.Text:= Format('文件名:%s',[GetUrlFileName(Edit3.Text)]);
label3.Text := Format('%s / %s', [BytesToStr(Progress),BytesToStr(ProgressMax)]);
end; end.
DELPHI TDownLoadURL下载网络文件的更多相关文章
- JAVA多线程下载网络文件
JAVA多线程下载网络文件,开启多个线程,同时下载网络文件. 源码如下:(点击下载 MultiThreadDownload.java) import java.io.InputStream; im ...
- Java读取并下载网络文件
CreateTime--2017年8月21日10:11:07 Author:Marydon import java.io.ByteArrayOutputStream; import java.io ...
- python下载网络文件
python下载网络文件 制作人:全心全意 下载图片 #!/usr/bin/python #-*- coding: utf-8 -*- import requests url = "http ...
- 【python】下载网络文件到本地
# 下载网络图片文件到本地 import urllib.request rsp=urllib.request.urlopen("http://n.sinaimg.cn/ent/transfo ...
- java 下载网络文件
1.FileUtils.copyURLToFile实现: import java.io.File; import java.net.URL; import org.apache.commons.io. ...
- python使用wget下载网络文件
wget是一个从网络上自动下载文件的自由工具.它支持HTTP,HTTPS和FTP协议,可以使用HTTP代理. ubuntu 安装wget pip install wget 从网络或本地硬盘下载文件(并 ...
- 解决FTPClient下载网络文件线程挂起问题
今天在windows上调试FTP下载文件时,出险线程假死,代码如下: if (inputStream != null) { byte[] data = null; ByteArrayOutputStr ...
- C#限速下载网络文件
代码: using System; using System.Collections.Concurrent; using System.Collections.Generic; using Syste ...
- 网络编程(一):用C#下载网络文件的2种方法
使用C#下载一个Internet上的文件主要是依靠HttpWebRequest/HttpWebResonse和WebClient.具体处理起来还有同步和异步两种方式,所以我们其实有四种组合. 1.使用 ...
随机推荐
- [jobdu]丑数
由于思维的惯性,用了queue.后来发现一要注意要用集合判重,二是每次往queue里放的多,后来溢出了,要用long long.但这样要用数组,集合,队列,内存多.效率是O(n*logn)的. #in ...
- 怎样在WINDOWS下面编译LIBCURL
我测试过,好像没OK This is a short note about building cURL with SSL support on Windows. Tools required: cUR ...
- RxJava开发精要1-从.NET到RxJava
原文出自<RxJava Essentials> 原文作者 : Ivan Morgillo 译文出自 : 开发技术前线 www.devtf.cn 转载声明: 本译文已授权开发者头条享有独家转 ...
- Apache CXF 例子
来自:http://www.cnblogs.com/frankliiu-java/articles/1641949.html Apache CXF 是一个开放源代码框架,是在Xfire 跟Celtix ...
- spring cloud官方文档提到的服务开发的12项要素。
I. Codebase 从一个代码库部署到多个环境. II. Dependencies 使用显式的声明隔离依赖,即模块单独运行,并可以显式管理依赖. III. Config 在系统外部存储配置信息. ...
- STL priority_queue sort 自定义比较终极模板
比较有两种重载,一种是类内部的bool operator<( 只有一个参数 ),当然bool operator< 也可以拿到类的外面:另外一种是写一个cmp,利用cmp返回作为sort的第 ...
- vi/vim 基本使用
摘要: 在minicom终端里修改开发板中的文件时,必须要用到vi,因为开发板中并不像开发主机那样,有gedit和kscope这样的编辑器:还有,即便是在开发主机上,也会经常用到vi,因为vi使用起来 ...
- MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类
MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型.是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器 ...
- 阿里云数加平台——BI报表使用概述和总结
先声明一点,本人写此文章初衷只为对前段时间的工作做些总结,并做个记录,以备日后查用,此外也顺便与他人分享一下.当然间接上也为阿里云的大数据平台做了个免费广告.以下开始正文. 首先进入数加服务的控制面板 ...
- App.config提示错误“配置系统未能初始化”
解决: "如果配置文件中包含 configSections 元素,则 configSections 元素必须是 configuration 元素的第一个子元素." 所以它前面如果有 ...