Ver Mensaje Individual
  #20  
Antiguo 27-09-2007
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Vamos a ver, el problema es que la pagina suelta un #0 en medio del texto, sin venir a cuento (al menos yo no veo porque lo hace). El carácter #0 (o carácter nulo) se utiliza para indicar el final de una cadena de texto, en delphi, en C y en muchos otros lenguajes. Cuando tu le pasas ese texto a un memo windows interpreta el #0 como el final del texto, por eso no muestra el resto de la cadena.

Una solución rápida es sustituir el carácter #0 por, por ejemplo, un espacio:
Código Delphi [-]
uses WinInet;

function DownloadToStream(Url: string; Stream: TStream): Boolean;
var
  hNet: HINTERNET;
  hUrl: HINTERNET;
  Buffer: PChar;
  BytesRead: DWORD;
  i: Integer;
begin
  Result := FALSE;
  hNet := InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if (hNet <> nil) then
  begin
    hUrl := InternetOpenUrl(hNet, PChar(Url), nil, 0,
      INTERNET_FLAG_RELOAD, 0);
    if (hUrl <> nil) then
    begin
      GetMem(Buffer,100*1024);
      try
        while (InternetReadFile(hUrl, Buffer, 100*1024, BytesRead)) do
        begin
          if (BytesRead = 0) then
          begin
            Result := TRUE;
            break;
          end;
          // Aqui sustituimos el caracter nulo por un espacio
          for i:= 0 to BytesRead - 1 do
            if Buffer[i] = #0 then
              Buffer[i]:= #32;
          Stream.WriteBuffer(Buffer^,BytesRead);
        end;
      finally
        FreeMem(Buffer);
      end;
      InternetCloseHandle(hUrl);
    end;
    InternetCloseHandle(hNet);
  end;
end;

// Por ejemplo
var
  Stream: TStringStream;
begin
  Stream:= TStringStream.Create('');
  try
    DownloadToStream('http://casacimar.com.bo/tarea.html',Stream);
    Memo1.Lines.Text:= Stream.DataString;
  finally
    Stream.Free;
  end;
end;
Responder Con Cita