WebBrowser直接LoadFromStream

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
如何不用Navigate调入文件,直接往TWebBrowse中写Html语句呢…… 我发现好象必须用webbrowser的ipersiststreaminit来save过的stream才能正确的被
load,用ie保存的就不行。我没太多时间,你再研究研究
下面的例子可以正确载入
begin
filestream:=TMemoryStream.Create;
browser1.Navigate('www.chinaren.com');
browser1.SaveTostream(filestream);
filestream.Position:=0;
browser2.LoadFromStream(filestream);
filestream.Free;
end;
function SaveToStream(AStream: TStream): HRESULT;
var
IpStream: IPersistStreamInit;
begin
with browser1 do
begin
while ReadyState <> READYSTATE_COMPLETE do
Forms.Application.ProcessMessages;
if Assigned(Document) then
begin
IpStream := Document as IPersistStreamInit;
Result := IpStream.save(TStreamAdapter.Create(AStream), TRUE);
end else Result := S_FALSE;
end;
end;
function Loadfromstream(AStream:TStream):hresult;
begin
with browser1 do
begin
if not Assigned(Document) then
begin
navigate2('about:blank',0,0,0,0);
while readystate <> READYSTATE_COMPLETE do Forms.Application.ProcessMessages;
end;
AStream.seek(0, 0);
Result := (Document as IPersistStreamInit).Load(TStreamadapter.Create(AStream));
end;
end;
 
后退
顶部