如何用Delphi实现在网页上下载文件。
解决方案 »
- 大家往panel上拖控件都用什么布局方式啊??
- 请问在DELPHI中如何控制其他应用程序的窗体,表单?
- 急,请问如何在程序中改变chart1的Series[0]的显示样子,现在是line,我想改成pie
- 有关字符串操作的两个问题,请高人相助
- 是系统结构问题吗?
- 超级Flash播放器(SuperFlashPlayer)软件策划[欢迎有兴趣的朋友共同参与]
- 请教关于鼠标消息相应顺序的问题!
- 高手请指教想在TStringGrid控件中实现当鼠标拖动时鼠标形状变形当停止拖动时鼠标形状回复原状怎么办
- 急!!请教各位大虾一个问题!!在线等待!!!
- 还是见了鬼的问题,sql server存取jpg图片的.
- 请高手赐教
- 请问如何在DELPHI里把数值转化成中文大写数值?如把198转化成壹佰玖拾捌?
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, Psock, NMHttp, ExtCtrls, jpeg;type
TForm1 = class(TForm)
NMHTTP1: TNMHTTP;
Button1: TButton;
Label1: TLabel;
edtURL: TEdit;
StatusBar1: TStatusBar;
Label2: TLabel;
lblTemp: TLabel;
Label4: TLabel;
lblFinal: TLabel;
procedure Button1Click(Sender: TObject);
procedure NMHTTP1Success(Cmd: CmdType);
procedure FormCreate(Sender: TObject);
procedure NMHTTP1Failure(Cmd: CmdType);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
NMHTTP1.Get(edtURL.text);
end;procedure TForm1.NMHTTP1Success(Cmd: CmdType);
var
fname:string;
buf:string;
pnewfile,poldfile:pchar;
i:integer;
begin
{ Copyright (C) Bowman }
{ [email protected] }
//retrive the tmp file
fname:=nmhttp1.body;
//retrive file name
for i:=length(edtURL.Text) downto 1 do
if edtURL.text[i]<>'/' then
buf:=edtURL.text[i]+buf
else
break;
//assign file name
Getmem(poldFile,length(fname)+1);
StrPCopy(poldFile,fname);
Getmem(pnewfile,length(buf)+1);
StrPCopy(pnewfile,buf);
//rename it
MoveFile(poldfile,pnewfile);
Freemem(poldfile);
Freemem(pnewfile);
//show infomation
statusbar1.Panels.Items[0].text:='download complete';
lblTemp.caption:= fname;
lblFinal.Caption:=buf;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
//store in file
NMHTTP1.InputFileMode:= TRUE;
NMHTTP1.TimeOut:=2000;
//set temp file name
NMHTTP1.Body:='Part.tmp';
NMHTTP1.Header:='Head.tmp';
end;procedure TForm1.NMHTTP1Failure(Cmd: CmdType);
begin
StatusBar1.Panels.Items[0].text:='Failed';
end;end.