S
softchina
Unregistered / Unconfirmed
GUEST, unregistred user!
我想把一段文字直接在浏览器中显示出来,我用了下面的程序,当点击
按钮的时候出现,Access violation at address XXXX in module
'project1.exe'.read of address FFFFFF.
请大家帮忙看一下,告诉我错在哪里,谢谢!!
(应该是IHtmlDocument出的错!)
unit unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,OleCtrls, SHDocVw, StdCtrls, Activex;
type
TForm1 = class(TForm)
Button1: TButton;
IE: TWebBrowser;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure ShowInWebBrowser(WebB:TWebBrowser;Str:String);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses comobj,mshtml;
procedure TForm1.Button1Click(Sender: TObject);
var
S:String;
begin
S:='<html><body><H1>This is a demo!!!</H1></body></html>';
ShowInWebBrowser(IE,S);
end;
procedure TForm1.ShowInWebBrowser(WebB:TWebBrowser;Str:String);
var
v: Variant;
HTMLDocument: IHTMLDocument2;
begin
HTMLDocument := WebB.Document as IHTMLDocument2;
v := VarArrayCreate([0, 0], varVariant);
v[0] := str;
HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
HTMLDocument.Close;
end;
initialization
OleInitialize(nil);
finalization
OleUninitialize;
end.
按钮的时候出现,Access violation at address XXXX in module
'project1.exe'.read of address FFFFFF.
请大家帮忙看一下,告诉我错在哪里,谢谢!!
(应该是IHtmlDocument出的错!)
unit unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,OleCtrls, SHDocVw, StdCtrls, Activex;
type
TForm1 = class(TForm)
Button1: TButton;
IE: TWebBrowser;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure ShowInWebBrowser(WebB:TWebBrowser;Str:String);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses comobj,mshtml;
procedure TForm1.Button1Click(Sender: TObject);
var
S:String;
begin
S:='<html><body><H1>This is a demo!!!</H1></body></html>';
ShowInWebBrowser(IE,S);
end;
procedure TForm1.ShowInWebBrowser(WebB:TWebBrowser;Str:String);
var
v: Variant;
HTMLDocument: IHTMLDocument2;
begin
HTMLDocument := WebB.Document as IHTMLDocument2;
v := VarArrayCreate([0, 0], varVariant);
v[0] := str;
HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
HTMLDocument.Close;
end;
initialization
OleInitialize(nil);
finalization
OleUninitialize;
end.