nikola_mk
asked on
Wininet help (downloading file)
Hi.
I use Wininet for downloading files from internet.
When I start with downloading the file, my project is bloked (freezed).
Please paste this function in your project and compile it.Try to move the
form and you will se my problem (the form can be moved when you like).
Please tell me how can I solve ths problem.
uses Wininet;
function GetInetFile
(const fileURL, FileName: String): boolean;
const BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: File;
sAppName: string;
begin
Result:=False;
sAppName := ExtractFileName(Applicatio n.ExeName) ;
hSession := InternetOpen(PChar(sAppNam e),
INTERNET_OPEN_TYPE_PRECONF IG,
nil, nil, 0);
try
hURL := InternetOpenURL(hSession,
PChar(fileURL),
nil,0,0,0);
try
AssignFile(f, FileName);
Rewrite(f,1);
repeat
InternetReadFile(hURL, @Buffer,
SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen)
until BufferLen = 0;
CloseFile(f);
Result:=True;
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSessi on)
end
end;
use:
var FileOnNet, LocalFileName: string
begin
FileOnNet:=
'http://www.clevercomponents.com/demo/inetsuite/v31/clInetSuiteDemoD6.exe';
LocalFileName:='c:\windows \desktop\c lInetSuite DemoD6.exe '
if GetInetFile(FileOnNet,Loca lFileName) =True then
ShowMessage('Download successful')
else
ShowMessage('Error in file download')
end;
Thank you
Nikola.
I use Wininet for downloading files from internet.
When I start with downloading the file, my project is bloked (freezed).
Please paste this function in your project and compile it.Try to move the
form and you will se my problem (the form can be moved when you like).
Please tell me how can I solve ths problem.
uses Wininet;
function GetInetFile
(const fileURL, FileName: String): boolean;
const BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: File;
sAppName: string;
begin
Result:=False;
sAppName := ExtractFileName(Applicatio
hSession := InternetOpen(PChar(sAppNam
INTERNET_OPEN_TYPE_PRECONF
nil, nil, 0);
try
hURL := InternetOpenURL(hSession,
PChar(fileURL),
nil,0,0,0);
try
AssignFile(f, FileName);
Rewrite(f,1);
repeat
InternetReadFile(hURL, @Buffer,
SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen)
until BufferLen = 0;
CloseFile(f);
Result:=True;
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSessi
end
end;
use:
var FileOnNet, LocalFileName: string
begin
FileOnNet:=
'http://www.clevercomponents.com/demo/inetsuite/v31/clInetSuiteDemoD6.exe';
LocalFileName:='c:\windows
if GetInetFile(FileOnNet,Loca
ShowMessage('Download successful')
else
ShowMessage('Error in file download')
end;
Thank you
Nikola.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.