FORM上放置一个按钮和WEBBrowser控件,uses mshtml则下面程序通过.
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('c:\a.htm');
end;procedure TForm1.loaded(ASender: TObject; const pDisp: IDispatch;
var URL: OleVariant);
begin
hdoc2:=webbrowser1.Document as IHTMLDocument2;
ShowMessage(hdoc2.body.innerHTML);
end;在VB里利用createDocumentFromUrl能够直接打开文档的.如
Private Doc As New MSHTML.HTMLDocument
Private iDoc As MSHTML.HTMLDocument
Set iDoc = Doc.createDocumentFromUrl(FileName, vbNullString)
请问DELPHI里如何也不借助WebBrowser直接象上面的VB一样打开一个文档?
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('c:\a.htm');
end;procedure TForm1.loaded(ASender: TObject; const pDisp: IDispatch;
var URL: OleVariant);
begin
hdoc2:=webbrowser1.Document as IHTMLDocument2;
ShowMessage(hdoc2.body.innerHTML);
end;在VB里利用createDocumentFromUrl能够直接打开文档的.如
Private Doc As New MSHTML.HTMLDocument
Private iDoc As MSHTML.HTMLDocument
Set iDoc = Doc.createDocumentFromUrl(FileName, vbNullString)
请问DELPHI里如何也不借助WebBrowser直接象上面的VB一样打开一个文档?
当然借助TWEBBrowser可以打开IHTMLDocument2,但我想在VB中不借助其他的能行的,DELPHI怎样也可以。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,MSHTML, ActiveX,comobj, OleCtrls, SHDocVw, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function GetHtml(const WebBrowser:TWebBrowser): string;
const
BufSize = $10000;
var
Size: Int64;
Stream: IStream;
hHTMLText: HGLOBAL;
psi: IPersistStreamInit;
begin
if not Assigned(WebBrowser.Document) then Exit; OleCheck(WebBrowser.Document.QueryInterface(IPersistStreamInit, psi));
try
hHTMLText := GlobalAlloc(GPTR, BufSize);
if 0 = hHTMLText then RaiseLastWin32Error; OleCheck(CreateStreamOnHGlobal(hHTMLText, True, Stream));
try
OleCheck(psi.Save(Stream, False)); Size := StrLen(PChar(hHTMLText));
SetLength(Result, Size);
CopyMemory(PChar(Result), Pointer(hHTMLText), Size);
finally
Stream := nil;
end;
finally
psi := nil;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
self.WebBrowser1.Navigate('www.google.cn');
end;procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
showmessage(gethtml(self.WebBrowser1));
end;end.