unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, EmbeddedWB, StdCtrls, ActiveX, MShtml;type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser: TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure WebBrowserDocumentComplete(Sender: TObject; const pDisp: IDispatch;
var URL: OleVariant);
private
{ Private declarations }
ms : TMemoryStream;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
const fpath = 'C:\Documents and Settings\Wxz\桌面\';
procedure TForm1.Button1Click(Sender: TObject);
var s : string;
begin
ms.Clear; s := fpath + 'main.HTM';
ms.LoadFromFile(s); ms.Seek(0,0);
if WebBrowser.Document <> nil then
(WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ms := TMemoryStream.Create;
WebBrowser.Navigate('about:blank');
end;procedure TForm1.WebBrowserDocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var s : string;
begin
s := URL;
if not ansiSameText(s,'about:blank') then begin
Delete(s,1,Length('about:blank'));
s := fpath + s; ms.Clear;
ms.LoadFromFile(s); ms.Seek(0,0);
if pDisp <> nil then begin
if (pDisp as IWebBrowser2).Document <> nil then
(((pDisp as IWebBrowser2).Document) as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
end;
end;
end;end.main.htm 中为 <html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head><frameset cols="200,*">
<frame name="contents" target="main" src="cont.html">
<frame name="main" src="face.htm" target="main" scrolling="auto">
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>
</html>
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, EmbeddedWB, StdCtrls, ActiveX, MShtml;type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser: TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure WebBrowserDocumentComplete(Sender: TObject; const pDisp: IDispatch;
var URL: OleVariant);
private
{ Private declarations }
ms : TMemoryStream;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
const fpath = 'C:\Documents and Settings\Wxz\桌面\';
procedure TForm1.Button1Click(Sender: TObject);
var s : string;
begin
ms.Clear; s := fpath + 'main.HTM';
ms.LoadFromFile(s); ms.Seek(0,0);
if WebBrowser.Document <> nil then
(WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ms := TMemoryStream.Create;
WebBrowser.Navigate('about:blank');
end;procedure TForm1.WebBrowserDocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var s : string;
begin
s := URL;
if not ansiSameText(s,'about:blank') then begin
Delete(s,1,Length('about:blank'));
s := fpath + s; ms.Clear;
ms.LoadFromFile(s); ms.Seek(0,0);
if pDisp <> nil then begin
if (pDisp as IWebBrowser2).Document <> nil then
(((pDisp as IWebBrowser2).Document) as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
end;
end;
end;end.main.htm 中为 <html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head><frameset cols="200,*">
<frame name="contents" target="main" src="cont.html">
<frame name="main" src="face.htm" target="main" scrolling="auto">
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>
</html>
const pDisp: IDispatch; var URL: OleVariant);
是face.htm 和 cont.html从TMemoryStream中写入到 frame 中去能写入,但WebBrowser不显示两个frame的内容