我用WebBrowser控制网页中的对象,像你说的两种方法:  
有两种写法:  
 
1:  
Uses  MSHTML          //IHTMLDocument2,IHTMLInputElement,IHTMLFormElement等在其中定义,必须加上该单元!  
 
var  
   Doc:IHTMLDocument2;  
   Input:IHTMLInputElement;  
   Form:IHTMLFormElement;  
begin  
Doc:=Webbrowser1.Document  as  IHTMLDocument2;  
Input:=  Doc.all.item('name',0)  as  IHTMLInputElement;  
                       //或者Input:=  IHTMLDocument2(Webbrowser1.Document).all.item('name',0)  as  IHTMLInputElement;  
Input.value:='Test';  
Input:=  Doc.all.item('pass',0)  as  IHTMLInputElement;  
                     //或者Input:=  IHTMLDocument2(Webbrowser1.Document).all.item('name',0)  as  IHTMLInputElement;  
Input.value:='123456';  
Form:=  Doc.all.item('alogon',0)  as  IHTMLFormElement;  
Form.submit;  
end;  
 
2:  
With  WebBrowser1.OleObject.document  do  
begin    
   all.item('name').value:='Test';  
   all.item('pass').value:='123456;  
   forms.item('alogon').submit;  
end;  
 
 
 
可是在没有Frame的情况下没问题(再次表示感谢!)。  
 
可拿到有Frame的页面里就不行了,我应该怎么改上面的那些代码呢?  
 
我要控制的对象在Frame:<frame  src="output.htm"  name="send">里。  
 
也就是说要控制的对象在“output.htm”里。  
 
我该怎么把Frame加到上面的代码里呢?  
 
救救我呀!  
 
 
 

解决方案 »

  1.   

    前段时间在考试,网上的比较少!var
      doc:IHTMLDocument2;
      win:IHTMLWindow2;
      framesCollection:IHTMLFramesCollection2;
      input:IHTMLInputElement;
      vFrame,ret:OleVariant;
    begin
      doc:=WebBrowser1.Document as IHTMLDocument2;
      framesCollection:=(doc.get_frames as IHTMLFramesCollection2);
      TVariantArg(vFrame).vt:=VT_UINT;
      TVariantArg(vFrame).iVal:=0;
      ret:=framesCollection.item(vFrame);
      TVariantArg(ret).pdispVal.QueryInterface(IID_IHTMLWindow2,win);
      input:=((win.document as IHTMLDocument2).all.item('name',0) as IHTMLInputElement);
      input.value:='Test';
    end;
      

  2.   

    http://www.bytesandmore.de/rad/cpp/files/TCppWebBrowserSrc.zip
    http://www.bytesandmore.de/rad/cpp/files/TCppWebBrowserExe.zip