Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Wininet help (downloading file)

Posted on 2003-10-27
5
Medium Priority
?
577 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 272 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 264 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 264 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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