Programalama > DELPHI

Etiketler: download

Ort. 0
Puan ver:
procedure gy_DownloadFile_to_file(const Url: string;File1,File2: String; Obj:TObject);
var
  NetHandle: HINTERNET;
  UrlHandle: HINTERNET;
  Buffer: array[0..1024] of Char;
  Toplam, BytesRead,NumWritten: dWord;
  ToF: file;
begin
  Toplam:=0;
  NetHandle := InternetOpen('Delphi 5.x', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);

  if Assigned(NetHandle) then
  begin
    UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);

    if Assigned(UrlHandle) then
      { UrlHandle valid? Proceed with download }
    begin
      FillChar(Buffer, SizeOf(Buffer), 0);
       AssignFile(ToF, file1);
       Rewrite(ToF, 1);	{ Record size = 1 }
      repeat
        FillChar(Buffer, SizeOf(Buffer), 0);
        InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
        Toplam := Toplam + BytesRead;
        if assigned(Obj) and ( Obj is TLabel) then
          TLabel(obj).caption := File2+' '+ FloatToStr(Toplam)+' Byte indi :)' ;
        BlockWrite(ToF, Buffer, BytesRead,NumWritten);
        Application.ProcessMessages;
      until BytesRead = 0;
      InternetCloseHandle(UrlHandle);
      CloseFile(ToF);
    end
    else
      { UrlHandle is not valid. Raise an exception. }
      raise Exception.CreateFmt('Cannot open URL %s', [Url]);

    InternetCloseHandle(NetHandle);
  end
  else
    { NetHandle is not valid. Raise an exception }
    raise Exception.Create('Unable to initialize Wininet');
end;


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.