function LoadFromStream(const AStream: TStream): HRESULT; begin AStream.seek(0, 0); Result := (Webbrowser1.Document as IPersistStreamInit).Load(TStreamadapter.Create(AStream)); end;procedure LoadFromStrings(const AStrings: TStrings); var M: TMemoryStream; begin M := TMemoryStream.Create; try AStrings.SaveToStream(M); Result := LoadFromStream(M); finally M.free; end; end;Try this way。
uses activex;initialization OleInitialize(nil);finalization OleUninitialize;取数据的话是: function GetWebBrowserText(IE: TWebBrowser): string; var Doc: IHtmlDocument2; Body: IHtmlElement; begin try Result := ''; Doc := IE.Document as IHtmlDocument2; if Doc = nil then Exit; Body := Doc.Body; if Body = nil then Exit; Result := Body.innerText; except end; end;写入数据的话是:(IE.Document as IHtmlDocument2).body.innertext:= '你要显示得html';操作之前一定要 navigate('about:blank'),初始化网页,
uses mshtml procedure TForm1.Button1Click(Sender: TObject); var sHTML: string; begin sHTML :=’〈P〉This is some Html text.〈/P〉’; WebBrowser1.OleObject.Document.body.innerHTML :=sHTML; end;
begin
AStream.seek(0, 0);
Result := (Webbrowser1.Document as
IPersistStreamInit).Load(TStreamadapter.Create(AStream));
end;procedure LoadFromStrings(const AStrings: TStrings);
var
M: TMemoryStream;
begin
M := TMemoryStream.Create;
try
AStrings.SaveToStream(M);
Result := LoadFromStream(M);
finally
M.free;
end;
end;Try this way。
OleInitialize(nil);finalization
OleUninitialize;取数据的话是:
function GetWebBrowserText(IE: TWebBrowser): string;
var
Doc: IHtmlDocument2;
Body: IHtmlElement;
begin
try
Result := '';
Doc := IE.Document as IHtmlDocument2;
if Doc = nil then Exit;
Body := Doc.Body; if Body = nil then Exit;
Result := Body.innerText;
except end;
end;写入数据的话是:(IE.Document as IHtmlDocument2).body.innertext:= '你要显示得html';操作之前一定要 navigate('about:blank'),初始化网页,
Body: IHtmlElement;出错,要引用哪个系统单元文件?
procedure TForm1.Button1Click(Sender: TObject);
var
sHTML: string;
begin
sHTML :=’〈P〉This is some Html text.〈/P〉’;
WebBrowser1.OleObject.Document.body.innerHTML :=sHTML;
end;