procedure TForm1.Timer1Timer(Sender: TObject);
begin
 Doc := WebBrowser1.Document as IHTMLDocument2;
 EditCookie.Text := Doc.cookie;
end;
我用这个代码格3秒得到WebBrowser1的cookie信息,但有些网站打开慢,超过了3杪,就出错了,有没法

解决方案 »

  1.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
     Doc := WebBrowser1.Document as IHTMLDocument2;
     if Doc <> nil then
       EditCookie.Text := Doc.cookie;
    end; 
      

  2.   

    webbrowse1中有个打开完成事件,在它里面输入下面语句
    procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    begin
    Doc := WebBrowser1.Document as IHTMLDocument2; 
     EditCookie.Text := Doc.cookie; 
    end;
      

  3.   

    procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; 
      const pDisp: IDispatch; var URL: OleVariant); 
    begin 
    Doc := WebBrowser1.Document as IHTMLDocument2;  
     EditCookie.Text := Doc.cookie;  
    end;这是最常用正确的办法如果用你的方法可以这样procedure TForm1.Timer1Timer(Sender: TObject); 
    begin 
     Doc := WebBrowser1.Document as IHTMLDocument2; 
     //等待WebBrowser1请求完成
     while(Doc=nil)do
     begin
       Sleep(200);
       //这是死循环,当然,你要设置一下循环的次数,比如等待3秒,大约是300次(只能说大约).因为执行循环过程也需要一点点时间
     end;
     EditCookie.Text := Doc.cookie; end;