unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,MSHTML, SHDOCVW,IdGlobal;
type
  TMainFrm = class(TForm)
    btnTest: TButton;
    edURL: TEdit;
    Label1: TLabel;
    procedure btnTestClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  MainFrm: TMainFrm;
implementation
{$R *.dfm}
procedure FillIEForm(aURL:string);
  procedure DoWithHtmlElement(aElementCollection:IHTMLElementCollection);
  var
    k:integer;
    vk:oleVariant;
    Dispatch: IDispatch;
    HTMLInputElement:IHTMLInputElement;
    HTMLSelectElement:IHTMLSelectElement;
    HTMLOptionElement: IHTMLOptionElement;
    HTMLTextAreaElement: IHTMLTextAreaElement;
    HTMLFormElement:IHTMLFormElement;
    HTMLOptionButtonElement:IHTMLOptionButtonElement;
  begin
    for k:=0 to aElementCollection.length -1 do
    begin
      Vk:=k;
      Application.ProcessMessages;
      Dispatch:=aElementCollection.item(Vk,0);
      if Succeeded(Dispatch.QueryInterface(IHTMLInputElement,HTMLInputElement)) then
      begin
        With HTMLInputElement do//单行文本
        begin
          if (UpperCase(Type_)='TEXT') or (UpperCase(Type_)='PASSWORD') then
          begin
            value:='text';
          end
          else if (UpperCase(Type_)='CHECKBOX') then//复选框
          begin
            checked:=true;
          end
          else if (UpperCase(Type_)='RADIO') then//单选框
          begin
            checked :=true;
          end;
        end;
      end
      else if Succeeded(Dispatch.QueryInterface(IHTMLSelectElement,HTMLSelectElement)) then
      begin
        With HTMLSelectElement do//下拉框
        begin
          selectedIndex :=1;
        end;
      end
      else if Succeeded(Dispatch.QueryInterface(IHTMLTEXTAreaElement,HTMLTextAreaElement)) then
      begin
        with HTMLTextAreaElement do//多行文本
        begin
          value :='textarea';
        end;
      end
      else if Succeeded(Dispatch.QueryInterface(IHTMLOptionElement,HTMLOptionElement)) then
      begin
        with HTMLOptionElement do//下拉选项
        begin
          //处理
        end;
      end
      else if SUCCEEDED(Dispatch.QueryInterface(IHTMLFormElement,HTMLFormElement))then
      begin
        with HTMLFormElement do//表单
        begin
          //处理
        end;
      end
      else if SUCCEEDED(Dispatch.QueryInterface(IHTMLOptionButtonElement,HTMLOptionButtonElement))then
      begin
        //不明
        //处理
      end
      else
        //showmessage('other');
        ;
    end;
  end;
var
  ShellWindow: IShellWindows;
  Web: IWebBrowser2;
  Dispatch: IDispatch;
  i,j:integer;
  IEAddress:string;
  HTMLDocument:IHTMLDocument2;
  ElementCollection:IHTMLElementCollection;
  FrameWindow:IHTMLWindow2;
  Vi,Vj:OLEVariant;
  HTMLFrameBase :IHTMLFrameBase ;
  HTMLFrameElement:IHTMLFrameElement ;
  HTMLIFrameElement:IHTMLIFrameElement;
begin
  ShellWindow := CoShellWindows.Create;
  for i:=0 to ShellWindow.Count -1 do
  begin
    Vi:=i;
    Dispatch:=ShellWindow.Item(Vi);
    if Dispatch=nil then continue;
    Dispatch.QueryInterface(IWebBrowser2,Web);
    if Web<>nil then
    begin
      IEAddress:=Web.LocationURL;
      if Pos(aURL,IEAddress)>0 then
      begin
        Web.Document.QueryInterface(IHTMLDocument2,HTMLDocument);
        if HTMLDocument<>nil then
        begin
          if HTMLDocument.frames.length =0 then//无框架
          begin
            ElementCollection:=HTMLDocument.Get_All;
            DoWithHtmlElement(ElementCollection);
          end
         else//有框架
          begin
            for j:=0 to HTMLDocument.frames.length -1 do
            begin
              Vj:=j;
              Dispatch:=HTMLDocument.frames.item(Vj);
//              if Succeeded(Dispatch.QueryInterface(IHTMLFrameBase,HTMLFrameBase)
              if Succeeded(Dispatch.QueryInterface(IHTMLWindow2,FrameWindow)) then
              begin
//                DoWithHtmlElement(FrameWindow.document.all);
              end;
            End;
          end;
        end;
      end;
    End;
  end;
end;
procedure TMainFrm.btnTestClick(Sender: TObject);
begin
  FillIEForm(edUrl.Text);
end;
end.

http://blog.csdn.net/iseekcode/article/details/4708400

Delphi中WebBrowser自动填表模板的更多相关文章

  1. Delphi中WebBrowser控件打开部分网站报"Invalid floating point operation”解决

    Delphi中WebBrowser控件打开部分网站报"Invalid floating point operation”解决 EmbeddedWBWebBrowserDelphi  最近用E ...

  2. delphi中webbrowser的用法

    WebBrowser1.GoHome; //到浏览器默认主页 WebBrowser1.Refresh; //刷新 WebBrowser1.GoBack; //后退 WebBrowser1.GoForw ...

  3. delphi中WEBBrowser网页html相互调用(一)

    1.基本操作1.1.激活 var doc,url:Olevariant ; begin url:='about:blank' ;//或者一个有实际意义的url WebBrowser1.Navigate ...

  4. delphi中Webbrowser疑难问题集锦<转>

    1.获得网页中变量值      htm中<script> var currID=123</script>      程序中可以这么调用 id := Form1.WebBrows ...

  5. Delphi 中的自动释放策略-转

    八.使用结构体而不是结构体指针: 很重要 一.指定 Owner 后, 随 Owner 连带释放: //uses Vcl.StdCtrls, Vcl.ExtCtrls; var panel: TPane ...

  6. Delphi 中的自动释放策略

    来自万一老师的博客:http://www.cnblogs.com/del/archive/2011/12/21/2295794.html ------------------------------- ...

  7. delphi中WebBrowser的parent改变时变成空白问题的解决(覆盖CreateWnd和DestroyWnd)

    这段时间在做一个delphi界面打开网页的功能,且此网页所在窗口可完整显示,可缩小到另一个窗口的panel上显示 可是在改变网页所在窗口时,WebBrowser控件变成了空白 上网google了半天, ...

  8. Delphi中WebBrowser拦截网页Alert对话框消息(转)

    interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, O ...

  9. delphi的webBrowser操作HTML研究

    测试例子: 外网电脑D:\TEST\delphiTest\webbrowsetest 参考文档: delphi 操作WebBrowser 元素值 http://hi.baidu.com/kinglik ...

随机推荐

  1. Qt学习之路(49): 通用算法

    今天开始的部分是关于Qt提供的一些通用算法.这部分内容来自C++ GUI Programming with Qt 4, 2nd Edition.   <QtAlgorithms>提供了一系 ...

  2. Windows Phone 8初学者开发—第22部分:用演示图板创建卷盘的动画

    原文 Windows Phone 8初学者开发—第22部分:用演示图板创建卷盘的动画 第22部分: 用演示图板创建卷盘的动画 原文地址:http://channel9.msdn.com/Series/ ...

  3. Ubuntu下安装和配置mysql

    一.检查 1.检查是否已经安装mysql whereis mysql 2.检查mysql服务是否已经启动 sudo netstat -tap | grep mysql 如果没有安装,下面就进行安装. ...

  4. 基于二叉树和数组实现限制长度的最优Huffman编码

    具体介绍详见上篇博客:基于二叉树和双向链表实现限制长度的最优Huffman编码 基于数组和基于链表的实现方式在效率上有明显区别: 编码256个符号,符号权重为1...256,限制长度为16,循环编码1 ...

  5. 改动项目APP名字后,在真机执行报错:The provisioning profile specified in your build settings (“haotian”) has an AppI

    错误提醒:The provisioning profile specified in your build settings ("haotian") has an AppID of ...

  6. BZOJ 3173: [Tjoi2013]最长上升子序列( BST + LIS )

    因为是从1~n插入的, 慢插入的对之前的没有影响, 所以我们可以用平衡树维护, 弄出最后的序列然后跑LIS就OK了 O(nlogn) --------------------------------- ...

  7. 稳定婚姻问题和Gale-Shapley算法(转)

    什么是算法?每当有人问作者这样的问题时,他总会引用这个例子:假如你是一个媒人,有若干个单身男子登门求助,还有同样多的单身女子也前来征婚.如果你已经知道这些女孩儿在每个男孩儿心目中的排名,以及男孩儿们在 ...

  8. js ajax调用请求

    <pre name="code" class="html"> function getAppList(env){ var data = {}; da ...

  9. 11.ThinkPHP 3.1.2 连贯操作

    ==================================================== 一.常用连贯操作 1.where 帮助我们设置查询条件 2.order 对结果进行排序 $ar ...

  10. Android中Parcelable序列化总结

    在使用Parcelable对android中数据的序列化操作还是比较有用的,有人做过通过对比Serializable和Parcelable在android中序列化操作对象的速度比对,大概Parcela ...