URL1
URL2
URL3
URL4
我用DELPHI做一个下载的工具,当用户点点URL的时候。进行下载。当用户点击另外一个连接时如果第一个没有完成下载。那么它处于等待状态。这个应该用DELHPI的什么来实现呢,刚开始学DELPHI,还不是很了解!
URL2
URL3
URL4
我用DELPHI做一个下载的工具,当用户点点URL的时候。进行下载。当用户点击另外一个连接时如果第一个没有完成下载。那么它处于等待状态。这个应该用DELHPI的什么来实现呢,刚开始学DELPHI,还不是很了解!
unit Unit2;interface
uses
Windows, Classes;type
TDownThread = class;
TManage = class(TThread)
private
FDownList: TStringList;
FLock: TRTLCriticalSection;
J: TThreadList;
procedure LockList;
procedure UnlockList;
protected
procedure Execute; override;
public
constructor Create(CreateSuspended: Boolean);
destructor Destroy; override;
function AddDownUrl(ADownPath: String): Boolean;
function GetFirst: string;
end; TDownThread = class(TThread)
private
FDwonUrl: string;
protected
function MyDown(const ADownUrl: string): Boolean; // 下载函数
procedure Execute; override;
public
constructor Create(CreateSuspended: Boolean; ADownUrl: string);
end;implementation
{ TManage }function TManage.AddDownUrl(ADownPath: String): Boolean;
begin
Result := False;
LockList;
try
if (FDownList.IndexOf(ADownPath) = -1) then
Result := FDownList.Add(ADownPath) > -1
finally
UnlockList;
end;
end;constructor TManage.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
FDownList := TStringList.Create;
InitializeCriticalSection(FLock);
end;destructor TManage.Destroy;
begin
LockList;
try
FDownList.Free;
inherited Destroy;
finally
UnlockList;
DeleteCriticalSection(FLock);
end;
end;procedure TManage.Execute;
var
DownPath: string;
DownThread: TDownThread;
begin
FreeOnTerminate := True;
inherited;
while not Terminated do
begin
if FDownList.Count > 0 then
begin
LockList;
DownPath := PChar(FDownList[0]);
UnlockList; DownThread := TDownThread.Create(False, DownPath);
DownThread.WaitFor;
DownThread.Free; LockList;
FDownList.Delete(0);
UnlockList;
end;
Sleep(3000);
end;
end;function TManage.GetFirst: string;
begin
if FDownList.Count > 0 then
Result := FDownList[0];
end;procedure TManage.LockList;
begin
EnterCriticalSection(FLock);
end;procedure TManage.UnlockList;
begin
LeaveCriticalSection(FLock);
end;{ TDownThread }constructor TDownThread.Create(CreateSuspended: Boolean; ADownUrl: string);
begin
inherited Create(CreateSuspended);
FDwonUrl := ADownUrl;
end;procedure TDownThread.Execute;
begin
inherited;
while True do
begin
if MyDown(FDwonUrl) then
Break;
end;
end;function TDownThread.MyDown(const ADownUrl: string): Boolean;
begin
Result := False;
Result := True;
end;end.