I want to download a file from the Internet, and InternetReadFile is a good and simple solution at first glance. In fact, too good to be true. Indeed, digging a bit, I began to realize that there were actually a lot of problems with him. People complain about all kinds of problems when using this code.
Problems may arise due to the fact that:
- the application is temporarily suspended until the HTTP server responds
- application freezes temporarily as internet connections break
- application is blocked because the HTTP server never responds
- InternetOpen (I just opened it recently) MUST be called only once during the life of the application
I could not find a complete example of how to use it correctly and reliably. Does anyone have an idea on how to implement it in a separate thread and timeout? There is another easy way to download a file from the Internet. Although I do not want to complicate my life with very large libraries such as the Jedi or even Indy.
function GetFileHTTP (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
Edit: These features check for internet connectivity. It also works on Win98.
{ Are we connected to the Internet? } function IsConnectedToInternet: Boolean; { Call SHELL32.DLL for Win < Win98 otherwise call URL.dll } var InetIsOffline: function(dwFlags: DWORD): BOOL; stdcall; begin Result:= FALSE; if IsApiFunctionAvailable('URL.DLL', 'InetIsOffline', @InetIsOffline) then Result:= NOT InetIsOffLine(0) else if IsApiFunctionAvailable('SHELL32.DLL', 'InetIsOffline', @InetIsOffline) then Result:= NOT InetIsOffLine(0) end;
I am using Delphi 7. Thanks a lot.
Edit:
Losing customers because the application freezes on first launch is an ideal recipe for losing money.
Writing code for Microsoft platform dependencies is bad. You never know if the client has IE xx installed
Installing material on a user's computer is a game with a weapon. This will have unpleasant consequences.
(more on this here: http://thesunstroke.blogspot.com/2010/06/programmig-like-there-is-no-ms-windows.html )
windows delphi
Sahara
source share