Y
yexiaoming
Unregistered / Unconfirmed
GUEST, unregistred user!
比如有如下一段html文字存于memo1中,如何在webbrowser中显示出来。请在行的大虾指点.
<html>
<body>
<p>hello world!</p>
</body>
</html>
之前查过的回答大概如下:但初次接触不知如何使用。
uses comobj, activex, mshtml, Variants;
procedure TForm1.htmlButtonClick(Sender: TObject);
var
html:string;
Stream: IStream;
hHTMLText: HGLOBAL;
psi: IPersistStreamInit;
DoC: IHTMLDocument2;
begin
Doc := WebBrowser1.Document as IHTMLDocument2;
SetLength(html, strtoint(DOC.Get_fileSize)+1);
html:=Doc.body.outerHTML;
if not Assigned(WebBrowser2.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(WebBrowser2.Document.QueryInterface(IPersistStreamInit, psi));
try
OleCheck(psi.InitNew);
OleCheck(psi.Load(Stream));
finally
psi := nil;
end;
finally
Stream := nil;
end;
end;
<html>
<body>
<p>hello world!</p>
</body>
</html>
之前查过的回答大概如下:但初次接触不知如何使用。
uses comobj, activex, mshtml, Variants;
procedure TForm1.htmlButtonClick(Sender: TObject);
var
html:string;
Stream: IStream;
hHTMLText: HGLOBAL;
psi: IPersistStreamInit;
DoC: IHTMLDocument2;
begin
Doc := WebBrowser1.Document as IHTMLDocument2;
SetLength(html, strtoint(DOC.Get_fileSize)+1);
html:=Doc.body.outerHTML;
if not Assigned(WebBrowser2.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(WebBrowser2.Document.QueryInterface(IPersistStreamInit, psi));
try
OleCheck(psi.InitNew);
OleCheck(psi.Load(Stream));
finally
psi := nil;
end;
finally
Stream := nil;
end;
end;