How to load an HTML document from a stream into a TCppWebBrowser.

By: mykle hoban

Abstract: This article describes how to load a document out of a stream (memory, file, etc.) into an instance of the Internet Explorer control.

Question

How can I do the equivalent of LoadFromStream within a TWebBrowser (IE control)?

Answer

Assuming that your HTML document is contained within Memo1, the code snipped below should illustrate how to load it from a stream into a TCppWebBrowser.


void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TMemoryStream *stm = new TMemoryStream();
  Memo1->Lines->SaveToStream(stm);

  IPersistStreamInit *psi;
  stm->Seek(0,0);

  //if you pass soOwned instead, the stream will be freed for you
  TStreamAdapter *sa = new TStreamAdapter(stm,soReference);

  if (SUCCEEDED(wb->Document->QueryInterface(IID_IPersistStreamInit,(void **)&psi)))
    psi->Load(*sa);

  delete stm;
}


Server Response from: ETNASC04