uses ActiveX,MSHTML //加上两个单元!
procedure ShowInWebBrowser(WebB:TWebBrowser;Str:String);
var
v: Variant;
HTMLDocument: IHTMLDocument2;
begin
HTMLDocument := WebB.Document as IHTMLDocument2;
if (assigned(HtmlDocument)) then begin
v := VarArrayCreate([0, 0], varVariant);
v[0] := str; //that is to be shown
HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
HTMLDocument.Close;
end;
end;
//调用
str= '输出内容 ';
ShowInWebBrowser(WebBrowser1, '输出内容 ');//可以为任意内容,包括HTML代码!
还有种方法,不如上面的灵活,但很简单实用!
str= '输出内容 ';
webbrowser1.Navigate( 'about: '+str);
|