天哪, delphi5的关于TWebBrower的help太简略了.
我只能说, 可以做到, 要看microsoft的Dynamic HTML reference.
我没有这个

解决方案 »

  1.   

    再稍微提示一点点,比如说是用TWebBrowser的方法,
    还是用文档对象的方法?如果用文档对象的话,那么TWebBrowser又该
    如何操作?
      

  2.   

    没见过这种方法,最好还是用临时文件,否则你HTML文档中的链接和JAVASCRIPT怎么办?而且我见过的软件中的实现方法也是用临时文件方法做的。
      

  3.   

    //写HTML
    procedure SetHtml(const WebBrowser:TWebBrowser; const Html: string);
    var
      Stream: IStream;
      hHTMLText: HGLOBAL;
      psi: IPersistStreamInit;
    begin
      if not Assigned(WebBrowser.Document) then Exit;  hHTMLText := GlobalAlloc(GPTR, Length(Html) + 1);
      if 0 = hHTMLText then RaiseLastWin32Error;  CopyMemory(Pointer(hHTMLText),
      PChar(Html), Length(Html));  OleCheck(CreateStreamOnHGlobal
      (hHTMLText, True, Stream));
      try
        OleCheck(WebBrowser.Document.
        QueryInterface(IPersistStreamInit, psi));
        try
          OleCheck(psi.InitNew);
          OleCheck(psi.Load(Stream));
        finally
          psi := nil;
        end;
      finally
        Stream := nil;
      end;
    end;//读HTML
    function GetHtml(const WebBrowser:TWebBrowser): string;
    const
      BufSize = $10000;
    var
      Size: Int64;
      Stream: IStream;
      hHTMLText: HGLOBAL;
      psi: IPersistStreamInit;
    begin
      if not Assigned(WebBrowser.Document) then Exit;  OleCheck(WebBrowser.Document.QueryInterface
      (IPersistStreamInit, psi));
      try
      //OleCheck(psi.GetSizeMax(Size));
        hHTMLText := GlobalAlloc(GPTR, BufSize);
        if 0 = hHTMLText then RaiseLastWin32Error;    OleCheck(CreateStreamOnHGlobal(hHTMLText,
        True, Stream));
        try
          OleCheck(psi.Save(Stream, False));      Size := StrLen(PChar(hHTMLText));
          SetLength(Result, Size);
          CopyMemory(PChar(Result), Pointer(hHTMLText), Size);
        finally
          Stream := nil;
        end;
      finally
        psi := nil;
      end;
    end;
      

  4.   

    意思对了,复杂复杂了……var
      OleStream: IStream;
      DelphiStream: TStream;DelphiStream := TStringStream.Create('<h1>I Love Delphi!</h1>'); // or any other TStream class instanceOleStream := TOleStream.Create(OleStream);tryOleStream.CopyFrom(DelphiStream, DelphiStream.Size);// of course if you have already valid IStream which contains what you want to load, use it directly. e.g URLOpenStream...  with (WebBrowser.Document as IPersistStreamInit) do
      begin
        OleCheck(InitNew);
        OleCheck(Load(OleStream)); // OleStream is a IStream interface pointer
      end;finally  OleStream.Free;
      DelphiStream.Free;end;最关键的一点,sundaynews说了,仅用流不能保留文档参考位置信息,所以这种情况下要用到Moniker了。即不用IPersistStreamInit接口,而用IPersistMoniker来加载IMoniker实现的对象的内容(详见URL Moniker文档)。