Avatar of Mathias
MathiasFlag for Germany

asked on 

Download File with ICS, IdHTTP or InternetReadfile

Hello,
I have a download function for files. It works in BDS 2006, but now I have CodeGear RAD 2009 und it doesn't :-( I think it's a problem that all strings are now in Unicode. I've tried with ICS und IdHTTP too, but there are also the headers (i couldn't strip them).
Can someone help me to have a workling solution in Delphi 2009?

Thx in advance

Bye, TDS
function TMainForm.GetHTML(AUrl: string): string;
var
  databuffer : array[0..4095] of char;
  ResStr : string;
  hSession, hfile: hInternet;
  dwindex,dwcodelen,dwread,dwNumber: cardinal;
  dwcode : array[1..20] of char;
  res    : pchar;
  Str    : pchar;
begin
   ResStr := '';
   Result := '';
  if pos('http://',lowercase(AUrl))=0 then
    AUrl:='http://'+AUrl;
   MainForm.WriteLog('GetHTML(): ' + AUrl);
  hSession:=InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
   If assigned(hSession) Then
  try
    hfile:=InternetOpenUrl(hsession, pchar(AUrl), nil, 0, INTERNET_FLAG_RELOAD, 0);
      if assigned(hfile) then
      try
      dwIndex  := 0;
      dwCodeLen := 10;
      HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex);
      res := pchar(@dwcode);
      dwNumber := sizeof(databuffer)-1;
      if (res ='200') or (res ='302') then
      begin
        while (InternetReadfile(hfile,@databuffer,dwNumber,DwRead)) AND (dwRead <>0) do
        begin
          databuffer[dwread]:=#0;
          Str := pchar(@databuffer);
          resStr := resStr + Str;
          Application.ProcessMessages;
        end;
      end
      else
        ResStr := 'Status: '+res;
      finally
        InternetCloseHandle(hfile);
     end;
  finally
    InternetCloseHandle(hsession);
  end;
   MainForm.WriteLog('GetHTML(): ' + ResStr);
   Result := ResStr;
   Result := '';
end;

Open in new window

Delphi

Avatar of undefined
Last Comment
smot
ASKER CERTIFIED SOLUTION
Avatar of smot
smot

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo