N
netsen
Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下 编译出错,我检查了,不知道为什么?!unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleCtrls, SHDocVw, StdCtrls;type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Memo1: TMemo; WebBrowser1: TWebBrowser; procedure WebBrowser1DocumentComplete(ASender: TObject; const pDisp: IDispatch; var URL: OleVariant); procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); 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:IPersistStreamInt; begin if not Assigned(WebBrowser.Document) then Exit; OleCheck(WebBrowser.Documen.QueryInterface(IPersistStreamInit,psi)); try hHTMLText:=GlobalAlloc(GPTR,bUFsize); OleCheck(CreatStreamOnHGlobal(hHTMLText,True,Stream)); try OlECheck(psi.Save(Stream,False)); Size:=StrLen(PChar(hHTMLText)); SetLength(Size); CopyMemory(PChar(Result)),Pointer((hHTMLText),Size); finally Stream :=nil; end; finally psi:=nil; end; end;procedure TForm1.FormCreate(Sender: TObject);begin Memo1.Clear;end;procedure TForm1.Button1Click(Sender: TObject);begin WebBorwser1.Navigate(Edit1.Text);end;procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject; const pDisp: IDispatch; var URL: OleVariant);begin if WebBrowser1.Application =pDisp then Memo1.Text :=GetHtml(WebBrowser1);end;end.