首页  编辑  

显示超文本

Tags: /超级猛料/Friends.网友专栏/zswang/函数大全/   Date Created:

(*//

标题:显示超文本

说明:在WebBrowser直接载入流,不通过文件

设计:Zswang

日期:2002-06-06

支持:wjhu111@21cn.com

//*)

///////Begin Source

uses ActiveX;

function ShowHtml(mWebBrowser: TWebBrowser; mStrings: TStrings): Boolean;

var

 vMemoryStream: TMemoryStream;

begin

 Result := False;

 if not (Assigned(mStrings) and Assigned(mWebBrowser)) then Exit;

 mWebBrowser.Navigate('about:blank');

 if not Assigned(mWebBrowser.Document) then Exit;

 vMemoryStream := TMemoryStream.Create;

 try

   mStrings.SaveToStream(vMemoryStream);

   try

     vMemoryStream.Position := 0;

     Application.ProcessMessages; // :)

     (mWebBrowser.Document as IPersistStreamInit).Load(

       TStreamAdapter.Create(vMemoryStream));

   except

     Exit;

   end;

 finally

   vMemoryStream.Free;

 end;

 Result := True;

end; { ShowHtml }

///////End Source

///////Begin Demo

procedure TForm1.Button1Click(Sender: TObject);

begin

 ShowHtml(WebBrowser1, Memo1.Lines);

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

 Memo1.Text :=

'<html>'#13#10 +

'<body bkcolor=#FF00FF><b>Hello Worlds!</b></body>'#13#10 +

'</html>'#13#10;

end;

///////End Demo