Solved

Wininet help (downloading file)

Posted on 2003-10-27
5
573 Views
Last Modified: 2010-10-05
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(Application.ExeName);
 hSession := InternetOpen(PChar(sAppName),
                INTERNET_OPEN_TYPE_PRECONFIG,
               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(hSession)
 end
end;



use:



var FileOnNet, LocalFileName: string
begin
 FileOnNet:=
  'http://www.clevercomponents.com/demo/inetsuite/v31/clInetSuiteDemoD6.exe';
 LocalFileName:='c:\windows\desktop\clInetSuiteDemoD6.exe'

 if GetInetFile(FileOnNet,LocalFileName)=True then
  ShowMessage('Download successful')
 else
  ShowMessage('Error in file download')

end;

Thank you

Nikola.


0
Comment
Question by:nikola_mk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 68 total points
ID: 9632418
Hi,

Try this:

...
  repeat
    Application.ProcessMessages; // add this line
    InternetReadFile(hURL, @Buffer,
                     SizeOf(Buffer), BufferLen);
    Application.ProcessMessages; // and this line
    BlockWrite(f, Buffer, BufferLen)
   until BufferLen = 0;
...

Regards, Geo
0
 
LVL 3

Assisted Solution

by:fibdev
fibdev earned 66 total points
ID: 9664226
Hi, I used to use Inet.  Didn't like it.  Try ICS It's free and powerful.
http://overbyte.delphicenter.com/frame_index.html

Place a httpCli component on your form and use code like this..

    Url := 'http://fibdev.com/bin/fpsetup.exe
    TrayIcon.Hint := 'Downloading Fibdev Fprint 3.0';

    if HTTPCli.State = httpReady then begin
    SI := TMemoryStream.Create;
    HTTPCli.URL := Url;
    try

      HTTPCli.RcvdStream := SI;

      sleep(500);
      HTTPCli.Get;
      // here SI contain the binary file
     SI.SaveToFile('.\fpsetup.exe');
     // You can launch it now or save that for later...
    // don't forget to free the memorystream when you're done
   SI.Free;
0
 
LVL 4

Assisted Solution

by:BedouinDN
BedouinDN earned 66 total points
ID: 9721086
Have you tried putting that function into another thread?
You could pass the URL file and the local file name to the thread as variables and call the function in the execute method of the thread and retrieve the value in the OnThreadTerminate event.
Works ok for me..
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question