프로그레스바로 표현도 가능하다.
uses 에 WinInet, ExtActns 선언되어 있어야 함.
 
TDownloadURL 이라는 클래스를 사용하는 것이 포인트.
 
아래는 bloodguy.com 에서 PC용 퍼즐보글을 다운로드하는 간단한 예제다.
 
 
procedure TfrmMain.Button1Click(Sender: TObject); 
var DownloadURL: TDownloadURL;  
const URL='http://www.bloodguy.com/DaTa/GaMe/Puzzle_Bobble.zip'
begin  

// "임시 인터넷 파일" 캐시에 있다면 삭제하고 시작하자. 

DeleteUrlCacheEntry(PChar(URL)); 

  

DownloadURL:=TDownloadURL.Create(nil); 

try 

DownloadURL.URL:=URL; 

DownloadURL.FileName:=ExtractFilePath(Application.ExeName)+'\퍼즐보글.zip'

  

DownloadURL.Execute; 

finally 

if Assigned(DownloadURL) then FreeAndNil(DownloadURL); 

end

end
 
 
프로그레스바에 연결도 가능하다.
TDownloadURL 객체의 OnDownloadProgress 이벤트에 함수를 연결해주면 된다.
우선 해당 폼의 public 에 이벤트함수를 선언한다.
 
 
public 

procedure URL_OnDownloadProgress(Sender: TDownloadURL; 

Progress, ProgressMax: Cardinal; 

StatusCode: TURLDownloadStatus; 

StatusText: String; var Cancel: Boolean); 

 
 
 
 
 
프로그레스바로 표시하기 (프로그레스바의 이름이 ProgressBar1 이라고 가정)
 
procedure TForm1.URL_OnDownloadProgress(Sender: TDownloadURL;  

Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; 

StatusText: String; var Cancel: Boolean); 

begin 

{ 프로그레스바 } 

ProgressBar1.Max:=ProgressMax;

ProgressBar1.Position:=Progress; 

  

{ 다운로드 진행표시? } 

Label1.Caption:=Format('%d/%d', [Progress, ProgressMax]); 

  

Refresh; 

Application.ProcessMessages; 

 

end
 
위의 이벤트 핸들러에서,
StatusText 를 이용해서 정보를 볼 수도 있고,
Cancel 을 이용해서 다운로드 중지도 가능하다.





Posted by bloodguy
,