Fejlmeddelelse v/ "closefile(F)" ved downloadning af fil via HTTP
Hej,jeg får en fejlmeddelelse i næst nederste kodelinie "CloseFile(F)" - Hvad gør jeg galt...??
function TMainFunctionForm.DownloadURL(const aUrl: string): Boolean;
var
hSession: HINTERNET;
hService: HINTERNET;
lpBuffer: array[0..1024 + 1] of Char;
dwBytesRead,akk,dwindex,dwcodelen: DWORD;
LocalFile:string;
F : File;
filesize : DWord;
dwcode:pointer;
res : pchar;
begin
Result := False;
LocalFile := 'C:\akljsdh.avi';
Assignfile(F,LocalFile);
Rewrite(F,1);
akk := 0;
dwcodeLen := 20;
dwIndex := 0;
hSession := InternetOpen('alds', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
if Assigned(hSession) then
begin
hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, INTERNET_FLAG_RELOAD, 0);
HttpQueryInfo(hService, HTTP_QUERY_CONTENT_LENGTH, @dwcode, dwcodeLen, dwIndex);
res := pchar(@dwcode);
edit1.text := res;
filesize := StrToInt(res);
if Assigned(hService) then
begin
Application.processmessages;
try
while True do
begin
dwBytesRead := 1024;
InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead);
BlockWrite(F, lpbuffer, dwBytesRead);
if dwBytesRead = 0 then break;
akk := akk + dwBytesRead;
Application.ProcessMessages;
ProgressBar1.Position := Round(akk/filesize * 100);
end;
Result := True;
finally
InternetCloseHandle(hService);
end;
end;
end;
finally
InternetCloseHandle(hSession);
end;
CloseFile(F);
end;
