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;