unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, SHDocVw, ActiveX, ComObj;
type
{ IPersistStream interface }
IPersistStream = interface(IPersist)
['{00000109-0000-0000-C000-000000000046}']
function IsDirty: HResult; stdcall; // 最后一次存盘后是否被修改
function Load(const stm: IStream): HResult; stdcall; // 从流中载入
function Save(const stm: IStream; fClearDirty: BOOL): HResult; stdcall; // 保存到流
function GetSizeMax(out cbSize: Longint): HResult; stdcall; // 取得保存所需空间大小
end;
{ IPersistStreamInit interface }
IPersistStreamInit = interface(IPersistStream)
['{7FD52380-4E07-101B-AE2D-08002B2EC713}']
function InitNew: HResult; stdcall; // 初始化
end;
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function SaveToWebBrowser(WebBrowser: TWebBrowser; AStream: TStream): HResult;
begin
AStream.seek(soFromBeginning, 0);
Result := (WebBrowser.Document as IPersistStreamInit).Load(TStreamadapter.Create(AStream));
end;
procedure ShowBlankPage(WebBrowser: TWebBrowser);
var
URL: OleVariant;
begin
URL := 'about:blank';
WebBrowser.Navigate2(URL);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ShowBlankPage(WebBrowser1);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
m: TMemoryStream;
begin
m := TMemoryStream.Create;
m.LoadFromFile('e:/1.htm');
m.Position := 0;
SaveToWebBrowser(WebBrowser1, m);
m.Free;
end;
end.