unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleCtrls, SHDocVw, StdCtrls, ExtCtrls, MSHTML; //在寫代碼之前我們先引用MSHTML單元 type TForm1 = class(TForm) Panel1: TPanel; Label1: TLabel; Label2: TLabel; EdURL: TEdit; EdCookies: TEdit; Button1: TButton; WebBrowser1: TWebBrowser; Button2: TButton; procedure Button1Click(Sender: TObject); procedure WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; Doc: IHTMLDocument2; //全局的變量 implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin //我們開始寫代碼 Webbrowser1.Navigate(EdURL.Text); //打開連接地址 //瀏覽器 部分 已經(jīng)搞定了 end; procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); begin if not Webbrowser1.Busy then //這句代碼的意思是 begin Doc:=Webbrowser1.Document as IHTMLDocument2; //將Webbrowser1.Document轉(zhuǎn)化為IHTMLDocument2接口 EdCookies.Text:=Doc.cookie; //將獲取到的COOKIES放到EdCookies.text里面 end; end; procedure TForm1.Button2Click(Sender: TObject); begin Doc.cookie:=EdCookies.Text; //設(shè)置Doc的COOKIES等于EdCookies.Text Webbrowser1.Refresh; //修改后 自動(dòng)刷新 end; end. |
|