uses Windows, Classes, Forms,
ActiveX, ComObj, SysUtils, SHDocVw;
procedure Document_SetHTML(Document: IDispatch;
const HTMLCode:
string);
var
ms: TStringStream;
begin
if Assigned(Document)
then
begin
ms := TStringStream.Create(HTMLCode);
try
ms.Seek(0, 0);
OleCheck((Document
as IPersistStreamInit).Load(TStreamAdapter.Create(ms)));
finally
ms.Free;
end;
end;
end;
function Document_GetHTML(Document: IDispatch):
string;
var
ms: TStringStream;
begin
Result := '
';
if Assigned(Document)
then
begin
ms := TStringStream.Create(Result);
try
OleCheck((Document
as IPersistStreamInit).Save(TStreamAdapter.Create(ms),False));
Result := ms.DataString;
finally
ms.Free;
end;
end;
end;
procedure WB_SetHTML(WebBrowser: TWebBrowser;
const HTMLCode:
string);
begin
if not Assigned(WebBrowser.Document)
then
WebBrowser.Navigate('
about:blank');
while WebBrowser.ReadyState < READYSTATE_INTERACTIVE
do
Application.ProcessMessages;
Document_SetHTML(WebBrowser.Document, HTMLCode);
end;
function WB_GetHTML(WebBrowser: TWebBrowser):
string;
begin
Result := Document_GetHTML(WebBrowser.Document);
end;