在ChinaOk (授人以鱼,不如授人以渔) 的帖子里有一段代码,
http://www.csdn.net/expert/topic/638/638770.xml?temp=.2672388
但是似乎有错误,
我对delphi还不是很了解
(WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms));------这句代码有错误吗,是什么意思,有高手能为我指点一下吗?

解决方案 »

  1.   

    "Loading HTML content from a Stream" in MSDN.
      

  2.   

    see "Loading  HTML  content  from  a  Stream  "  in  MSDN.
      

  3.   

    masterz()  MS的方法对于TOP 帧是有效的,但如果我的页面中包含了多个帧,那么就不能能获得正确的IPersistStreamInit Interface 了! CComPtr<IHTMLFramesCollection2> pFrameCol ;
    hr = m_pMainDoc->get_frames(&pFrameCol);
    ASSERT(pFrameCol != NULL);
    _variant_t vIndex("MainFrame");
    _variant_t vDispatch;
    hr = pFrameCol->item(&vIndex,&vDispatch);
    ASSERT(SUCCEEDED(hr));
    CComPtr<IHTMLWindow2> pIWin2;
    hr = vDispatch.pdispVal->QueryInterface(IID_IHTMLWindow2, (void**)&pIWin2);
    ASSERT(pIWin2 != NULL);

    #ifdef _DEBUG
    BSTR bsName;
    hr = pIWin2->get_name(&bsName);
    ASSERT(SUCCEEDED(hr));

    CString strName(bsName);
    ASSERT(strName == "MainFrame");
    #endif
    hr = pIWin2->get_document(&m_pMainFrameDoc);
    ASSERT(SUCCEEDED(hr)); CComQIPtr<IPersistStreamInit>pPSI(m_pMainFrameDoc);


    HRESULT hr = pPSI->InitNew(); //这里返回错误代码E_NOTIMPL
    如果说从 m_pMainDoc 查询到的IPersistStreamInit接口,调用InitNew()方法肯定是成功的! 如此说来,如果是帧,则不能用Loading HTML content from a Stream 方法更新页面了?用write可以,但如果页面复杂或者大一点,就会出现堆分配错误!如何解决呢????
      

  4.   

    Note  In Microsoft&reg; Internet Explorer 5, more than one call to the Load method of the IPersist  interfaces is supported. In earlier versions, only one call to Load per instance of MSHTML is supportedBUG: IPersistStreamInit Not Available for a FRAME in a FRAMESET Q271868
    The information in this article applies to:Microsoft Internet Explorer (Programming) version 5.5You can use the IHTMLDocument2::write method to add content to the WebBrowser control. Make sure that you call the IHTMLDocument2::open method first and the IHTMLDocument2::close method last. To obtain the IHTMLDocument2 interface, perform the following steps: <!--这里要加上一步(MSDN居然漏了)从得到的框架IDispatch查询IWebbrowser2接口>Load a blank file into the WebBrowser control.
    Call the IWebBrowser2::get_Document method to obtain the IDispatch interface of the document.
    Call QueryInterface on the IDispatch pointer, and ask for IHTMLDocument2.
    This code does not work for Internet Explorer versions 5.01 and earlier because these versions cannot obtain the IWebBrowser2 control (and therefore IHTMLDocument2) of a FRAME that was created using IHTMLDocument2::write.