Delphi’de hazır olarak gelmekte olan TDownloadURL adlı bir Action var. Bu Action internetten dosya indirme islemini cok kolaylastiriyor. Download islemi sirasinda meydana gelen her turlu olayi isleyebilmemiz icin bize OnDownloadProgess adli bir olay sunuyor. Biz simdi bu olayi kullanarak internetten dosya indirirken o ana kadar inen byte miktarini hem title da hem de bir progressbar uzerinde gosterecez.

Ilgili actionu kullanabilmek icin uses satirina ExtActns unitini ekleyelim.

Formun public alanina asagida ki sekilde bir procedure tanimlayalim. Bu TDownloadUrl nesnemizin OnDownloadProgress olayina atayacagimiz metodumuz.

Public
procedure URL_OnDownloadProgress(Sender: TDownLoadURL;
Progress, ProgressMax: Cardinal;
StatusCode: TURLDownloadStatus;
StatusText: String; var Cancel: Boolean) ;

bu da ilgili metodun govdesi.


procedure TForm17.URL_OnDownloadProgress(Sender: TDownLoadURL;
Progress, ProgressMax: Cardinal;
StatusCode: TURLDownloadStatus;
StatusText: String; var Cancel: Boolean);

begin
ProgressBar1.Max:= ProgressMax;
ProgressBar1.Position:= Progress;
Application.ProcessMessages;
Caption := FormatFloat('#,###',Progress) + ' byte / ' + FormatFloat('#,###',ProgressMax) + ' byte';
end;

Metod bize cok sayida parametre veriyor. Bu paremetleri kullanarak bir cok islem yapmak mumkun ama biz simdilik sadece Progress ve ProgressMAx parametrelerini kullanacaz.

Progress = o ana kadar inen byte miktari
ProgressMax = dosyanin toplam byte cinsinden boyutu

bu da TDownloadUrl nesnemizi calistiran dugmenin kodu.


procedure TForm17.Button1Click(Sender: TObject);
begin
with TDownloadURL.Create(self) do
try
URL:=edit1.Text;
FileName := 'inendosya.exe';
OnDownloadProgress := URL_OnDownloadProgress;
ExecuteTarget(nil);
finally
Free;
end;

end;

download.JPG

5 Responses to “Internetten Dosya indirmek”
  1. thelvaci says:

    Eline sağlık güzel bir tip.

  2. Ansugo says:

    Bu çok iyi bir tip olacak. Tam da işime yarayacağı günde ilaç gibi geldi.

  3. ferhan says:

    I must do this proggramm. But EXTACTNS is not available in my computer. I use Delphi5. Perhaps You give me wrong code. Everybody is always doing like this. wrong codes, missing codes. You are one of them. AGAIN:

    I CANT download file FROM INTERNET…

  4. Ansugo says:

    This code works fine. I’ve tested it.

  5. alper says:

    çok teşekkurler geyte guzel calişiyor

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>