P
pzh509
Unregistered / Unconfirmed
GUEST, unregistred user!
整个程序是这样的:在主窗口中有一个button按钮,两个edit文本框(用于输入ftp服务器
里要下载的文件名),
当按下button按钮后,创建两个线程使它们同时下载(采用IDFTP组件)
线程的整个代码如下:
unit Unit2;
interface
uses
Classes,IdFTP,Dialogs,StdCtrls;
type
dlthread = class(TThread)
private
{ Private declarations }
myidftp:tidftp;
mysavedialog:tsavedialog;
myedit:tedit;
protected
procedure Execute; override;
procedure download;//下载
public
constructor create(idftp:tidftp;savedialog:tsavedialog;aedit:tedit);
end;
implementation
constructor dlthread.create(idftp:tidftp;savedialog:tsavedialog;aedit:tedit);
begin
inherited create(false);
myidftp:=idftp;
mysavedialog:=savedialog;
myedit:=aedit;
freeonterminate:=true;//线程运行结束后,使线程自动释放本身的资源
end;
procedure dlthread.download;
begin
if mysavedialog.Execute then
begin
myidftp.TransferType:=ftbinary;//下载模式
myidftp.Get(myedit.Text,mysavedialog.FileName,true);//开始下载,mysavedialog.FileName存放 //的是下载到客户端的文件名
end;
end;
procedure dlthread.Execute;
begin
{ Place thread code here }
synchronize(download);
if terminated then
exit;
end;
end.
主窗口的主要代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var:
threadrunning:integer;//标识正在运行的线程数目
mydownthread1:dlthread;
mydownthread2:dlthread;
begin
threadrunning:=2;
mydownthread1:=dlthread.create(idftp1,savedialog1,edit1);
mydownthread1.OnTerminate:=threaddone;
mydownthread2:=dlthread.create(idftp1,savedialog2,edit2);
mydownthread2.OnTerminate:=threaddone;
end;
procedure TForm1.threaddone(sender:tobject);
begin
dec(threadrunning);
end;
但为什么它们不会同时下载?(运行结果是:等到第一个下载完后再接着下载另一个,
而实际上synchronize()函数是可以使线程同步执行的啊!)该怎么解决??
还有一个问题是:采用IDftp组件怎样做到断点传输??
里要下载的文件名),
当按下button按钮后,创建两个线程使它们同时下载(采用IDFTP组件)
线程的整个代码如下:
unit Unit2;
interface
uses
Classes,IdFTP,Dialogs,StdCtrls;
type
dlthread = class(TThread)
private
{ Private declarations }
myidftp:tidftp;
mysavedialog:tsavedialog;
myedit:tedit;
protected
procedure Execute; override;
procedure download;//下载
public
constructor create(idftp:tidftp;savedialog:tsavedialog;aedit:tedit);
end;
implementation
constructor dlthread.create(idftp:tidftp;savedialog:tsavedialog;aedit:tedit);
begin
inherited create(false);
myidftp:=idftp;
mysavedialog:=savedialog;
myedit:=aedit;
freeonterminate:=true;//线程运行结束后,使线程自动释放本身的资源
end;
procedure dlthread.download;
begin
if mysavedialog.Execute then
begin
myidftp.TransferType:=ftbinary;//下载模式
myidftp.Get(myedit.Text,mysavedialog.FileName,true);//开始下载,mysavedialog.FileName存放 //的是下载到客户端的文件名
end;
end;
procedure dlthread.Execute;
begin
{ Place thread code here }
synchronize(download);
if terminated then
exit;
end;
end.
主窗口的主要代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var:
threadrunning:integer;//标识正在运行的线程数目
mydownthread1:dlthread;
mydownthread2:dlthread;
begin
threadrunning:=2;
mydownthread1:=dlthread.create(idftp1,savedialog1,edit1);
mydownthread1.OnTerminate:=threaddone;
mydownthread2:=dlthread.create(idftp1,savedialog2,edit2);
mydownthread2.OnTerminate:=threaddone;
end;
procedure TForm1.threaddone(sender:tobject);
begin
dec(threadrunning);
end;
但为什么它们不会同时下载?(运行结果是:等到第一个下载完后再接着下载另一个,
而实际上synchronize()函数是可以使线程同步执行的啊!)该怎么解决??
还有一个问题是:采用IDftp组件怎样做到断点传输??