小弟最近做一个小程序,可是下面的代码老是不能正常工作
特来请教
var
ShellWindow: IShellWindows;nCount: integer;spDisp: IDispatch;i,j: integer;vi: OleVariant;IE1: IWebBrowser2;IDoc1: IHTMLDocument2;beginShellWindow := CoShellWindows.Create;nCount := ShellWindow.Count;for i := 0 to nCount - 1 dobeginvi := i;spDisp := ShellWindow.Item(vi);if spDisp = nil then continue;spDisp.QueryInterface( iWebBrowser2, IE1 );if IE1 <> nil thenbeginIE1.Document.QueryInterface(IHTMLDocument2,iDoc1);if iDoc1 <> nil thenie1.Quitend;end;end;
上面的代码有的时候行,有的时候不行,主要是这两个地方
spDisp.QueryInterface( iWebBrowser2, IE1 );
IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);诸位仁兄有没有办法解决?  

解决方案 »

  1.   

    上面的代码有的时候行,有的时候不行,主要是这两个地方 
    spDisp.QueryInterface( iWebBrowser2, IE1 ); 
    IE1.Document.QueryInterface(IHTMLDocument2,iDoc1); 诸位仁兄有没有办法解决?  编译通过
    有的时候执行可以抓到网页内容
    但是有的时候抓不到
    有时是spDisp.QueryInterface( iWebBrowser2, IE1 ); 
    出现异常
    有时是IE1.Document.QueryInterface(IHTMLDocument2,iDoc1); 
    出现异常
      

  2.   

    http://topic.csdn.net/t/20020716/21/879453.html#