将http://www.xxx.com/a.gif的文件内容拷贝到TStream中
象TFileStream(FileName,fmOpenRead)一样

解决方案 »

  1.   

    我正好也需要这样一个东东,关注一下另外,有这样的Image控件吗?
      

  2.   

    考虑xmlhttp,在msxml包中就有,应该可以完成你的要求的,比较方便
      

  3.   

    //uses UrlMon;
    function DownloadFile(SourceFile, DestFile: string): Boolean;
    begin
      try
        Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
      except
        Result := False;
      end; 
    end; procedure TForm1.Button1Click(Sender: TObject);
    begin
      if DownloadFile('http://www.xxx.com/a.gif', ExtractFilePath(Application.ExeName) + 'a.gif') then begin
      {再把文件内容拷贝到TStream}
      end;
    end;説明:先下載再看
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      strm: TMemoryStream;
    begin
      strm := TMemoryStream.Create;
      try
        IdHTTP1.Get('http://www.xxx.com/a.gif', strm);
      finally
        Edit1.Text := IdHTTP1.Response.ResponseText;
      end;
    end;説明:也可用「TIdHTTP」控件直接将内容拷贝到TStream中。
      

  5.   

    请教cronuz(cronus):1: //uses UrlMon;
       UrlDownloadToFile(...);是否支持全部Url协议,如file:// mshtml:// res://等
    2: 同样,IdHTTP1.Get呢?另,以下代码执行总出错
    function MyFun(...);
      var   Resp : TMemoryStream;
      FileStream : TFileStream;
    begin
      HTTPReqResp1.URL := 'http://www.china.com';//
      HTTPReqResp1.UseUTF8InHeader := true;
      HTTPReqResp1.Send('');
      Resp := TMemoryStream.Create;
      Resp.SetSize(65535); 
      HTTPReqResp1.Receive(0,Resp);
    出错在最后一句,即HTTPReqResp1.Receive(0,Resp);
    错误信息为"无效句柄"
      

  6.   

    l_xiaofeng(流水不腐) : 不明白?
    cronuz(cronus):
      你给出的第一个方法,试过,可以,不过要存储临时文件,所以第二方法合理一些
      

  7.   

    另:又有问题请教:
    为什么
    (WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame') as IWebBrowser.Document.Url

    (WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame') as IWebBrowser.Document.Location
    的值有时是IFrame中页面的地址
    有时又是主页面的地址
    摸不着头脑,望各位大侠有以教我
      

  8.   

    另:又有问题请教:
    为什么
    (((WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame').item(0,0) as IWebBrowser).Document as IHTMLDocument2).Url

    (((WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame').item(0,0) as IWebBrowser).Document as IHTMLDocument2).Location
    的值有时是IFrame中页面的地址
    有时又是主页面的地址
    摸不着头脑,望各位大侠有以教我