怎样显示内存中的html代码?(100分)

  • 主题发起人 主题发起人 lukee
  • 开始时间 开始时间
L

lukee

Unregistered / Unconfirmed
GUEST, unregistred user!
在Memo中有一段标准的html代码,我怎样在不将代码存入文件的情况下,直接在
WebBrowser中正确显示出来?
 
接着:

procedure tatonreg.loaddocument;
var
m:tmemorystream;
begin
M := TMemoryStream.Create;
memo1.Lines.SaveToStream(M);
M.seek(0, 0);
if not Assigned(ie.document) then begin
ie.navigate('about:blank');
while ie.readystate READYSTATE_COMPLETE do Forms.Application.ProcessMessages;
end;
(ie.Document as IPersistStreamInit).Load(TStreamadapter.Create(M));
end;
 
while ie.readystate READYSTATE_COMPLETE do Forms.Application.ProcessMessages;
上面这句话的readystate后面是否有一个等于号?

还有,我编译这段代码不通过,告诉我不认识IPersistStreamInit。为什么?
 
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.
 
多人接受答案了。
 
后退
顶部