S
sducn
Unregistered / Unconfirmed
GUEST, unregistred user!
mainform部分代码
procedure TMain.GetThread;
var
i: integer;
start: array[1..100] of integer;
last: array[1..100] of integer;
//改用了数组,也可不用
fileName: string;
begin
fileName := aFile;
MyThread:= TDownLoad.Create(ListView1,aURL, aFile);
tcount:=tcount+1;
i := i + 1;
sleep(10);
end;
myurl:=url;
aurl:=url;
myurl1:=geturl(myurl);
myurl:=geturl(myurl);
aFile := GetURLFileName(aURL);
//得到文件名
if myurl='exe' then
begin
if (checkurl0(aFile)=1) or(checkurl0(aFile)>1) then
begin
tcount := 0;
aURL := aurl;
//下载地址
aFile:=aFile;
j := 1;
aFileSize := GetFileSize(aURL);
avg := trunc(aFileSize / nn);
lcount:=ListView1.Items.Count;
EaPopup1.PopUp('公告',aFile+'已添加',3);
try
GetThread();
MyThread[j].Resume;
//唤醒线程
j := j + 1;
except
Showmessage('创建线程失败!');
Exit;
end;
end
else
begin
EaPopup1.PopUp('公告','文件'+aFile+'重复',3);
exit;
end;
end;
{thead部分代码}
constructor TDownLoad.Create(const AListView: TListView;aURL, aFile: string);
begin
FListView := AListView;
FreeOnTerminate := true;
tURL := aURL;
tFile := aFile;
with AListView.Items.Adddo
begin
Caption:='';
SubItems.Add(tFile);
SubItems.Add(tURL);
SubItems.Add('未知');
SubItems.Add('0KB');
SubItems.Add('未知');
SubItems.Add('0%');
SubItems.Add('未知');
Data := Self;
end;
inherited create(true);
end;
procedure TDownLoad.Execute;
var
I: Integer;
begin
do
wnLodeFile;
end;
procedure TDownLoad.DownLodeFile;
var
filepath:string;
tStream: TFileStream;
myidhttp:TIdHTTP;
begin
temhttp := TIdHTTP.Create(nil);
temhttp.onWorkbegin
:= main.idhttp1Workbegin
;
temhttp.HandleRedirects :=true;
temhttp.onwork := main.idhttp1Work;
temhttp.onStatus := main.idhttp1Status;
main.IdAntiFreeze1.OnlyWhenIdle := False;
//设置使程序有反应.
filepath:=ExtractFilePath(ParamStr(0));
if FileExists(filepath+'/DownLoadFiles/'+temFileName) then
//如果文件已经存在
begin
tStream := TFileStream.Create(filepath+'/DownLoadFiles/'+tFile, fmOpenWrite);
end
else
begin
tStream := TFileStream.Create(filepath+'/DownLoadFiles/'+tFile, fmCreate);
end;
try
temhttp.Get(tURL, tStream);
//开始下载
except
main.StatusBar1.Panels[0].Text:=tFile+'下载出错...';
tStream.Free;
Exit;
end;
freeandnil(tstream);
temhttp.Disconnect;
end;
procedure TMain.GetThread;
var
i: integer;
start: array[1..100] of integer;
last: array[1..100] of integer;
//改用了数组,也可不用
fileName: string;
begin
fileName := aFile;
MyThread:= TDownLoad.Create(ListView1,aURL, aFile);
tcount:=tcount+1;
i := i + 1;
sleep(10);
end;
myurl:=url;
aurl:=url;
myurl1:=geturl(myurl);
myurl:=geturl(myurl);
aFile := GetURLFileName(aURL);
//得到文件名
if myurl='exe' then
begin
if (checkurl0(aFile)=1) or(checkurl0(aFile)>1) then
begin
tcount := 0;
aURL := aurl;
//下载地址
aFile:=aFile;
j := 1;
aFileSize := GetFileSize(aURL);
avg := trunc(aFileSize / nn);
lcount:=ListView1.Items.Count;
EaPopup1.PopUp('公告',aFile+'已添加',3);
try
GetThread();
MyThread[j].Resume;
//唤醒线程
j := j + 1;
except
Showmessage('创建线程失败!');
Exit;
end;
end
else
begin
EaPopup1.PopUp('公告','文件'+aFile+'重复',3);
exit;
end;
end;
{thead部分代码}
constructor TDownLoad.Create(const AListView: TListView;aURL, aFile: string);
begin
FListView := AListView;
FreeOnTerminate := true;
tURL := aURL;
tFile := aFile;
with AListView.Items.Adddo
begin
Caption:='';
SubItems.Add(tFile);
SubItems.Add(tURL);
SubItems.Add('未知');
SubItems.Add('0KB');
SubItems.Add('未知');
SubItems.Add('0%');
SubItems.Add('未知');
Data := Self;
end;
inherited create(true);
end;
procedure TDownLoad.Execute;
var
I: Integer;
begin
do
wnLodeFile;
end;
procedure TDownLoad.DownLodeFile;
var
filepath:string;
tStream: TFileStream;
myidhttp:TIdHTTP;
begin
temhttp := TIdHTTP.Create(nil);
temhttp.onWorkbegin
:= main.idhttp1Workbegin
;
temhttp.HandleRedirects :=true;
temhttp.onwork := main.idhttp1Work;
temhttp.onStatus := main.idhttp1Status;
main.IdAntiFreeze1.OnlyWhenIdle := False;
//设置使程序有反应.
filepath:=ExtractFilePath(ParamStr(0));
if FileExists(filepath+'/DownLoadFiles/'+temFileName) then
//如果文件已经存在
begin
tStream := TFileStream.Create(filepath+'/DownLoadFiles/'+tFile, fmOpenWrite);
end
else
begin
tStream := TFileStream.Create(filepath+'/DownLoadFiles/'+tFile, fmCreate);
end;
try
temhttp.Get(tURL, tStream);
//开始下载
except
main.StatusBar1.Panels[0].Text:=tFile+'下载出错...';
tStream.Free;
Exit;
end;
freeandnil(tstream);
temhttp.Disconnect;
end;