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.使用 ...
随机推荐
- [状压dp]POJ1185 炮兵阵地
中文题 题意不再赘述 对于中间这个“P” 根据dp的无后效性 我们只需考虑前面的 就变成了 只需考虑: 也就是状压前两行 具体与HDOJ的4539类似: 看HDOJ 4539 仅仅是共存状态的判断不同 ...
- *[topcoder]LittleElephantAndBalls
http://community.topcoder.com/stat?c=problem_statement&pm=12758&rd=15704 topcoder的题经常需要找规律,而 ...
- More on 1Password’s Components
Stefan van As of 1Password fame sent me a more exhaustive list of the libraries and tools used in 1P ...
- Android Studio 快捷键 for Mac OS X 10.5+
Action Mac OSX Win/Linux 注释代码(//) Cmd + / Ctrl + / 注释代码(/**/) Cmd + Option + / Ctrl + Alt + / 格式化代码 ...
- 请问什么是UTF字符串?
utf是编码方式,一般而言是国际性质的编码格式,有utf-8,utf-9,utf-16等多种形式,是最高级别的编码方式,也就是说如果你要读取的数据流设置成utf编码的话就要用到相应的编码方式来读取了, ...
- SQL Server触发器以及如何在SQL Server Manager中调试触发器
·只有inserted表有数据时,当前操作为insert:·inserted和deleted两张表都有数据时,当前操作为update:·只有deleted表有数据时,当前操作为delete. 1. C ...
- 查看tablespace的使用情况
by tablespace(使用单位G): SELECT a.tablespace_name,(all_size-b.unuse_size) use_size,b.unuse_size,a.all_s ...
- Selenium 实现联想下拉框
直接在文本框输入字符,并不能实现联想下拉框, 第一种方式:强制执行js driver.FindElement(By.Id("top_search_input")).SendKeys ...
- bzoj 1879 [Sdoi2009]Bill的挑战(状压DP)
Description Input 本题包含多组数据. 第一行:一个整数T,表示数据的个数. 对于每组数据: 第一行:两个整数,N和K(含义如题目表述). 接下来N行:每行一个字符串. Output ...
- Android webView 中loadData方法加载 带中文时出现乱码
WebView出现乱码用LoadData方法来解析html的,但是据说这是官方的一个BUG,不能用来解析中文. 采用loadDataWithBaseURL的方法,其中codeingType设置为utf ...