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. C++赋值运算符与赋值表达式

    赋值运算符 赋值符号“=”就是赋值运算符,它的作用是将一个数据赋给一个变量.如“a=3”的作用是执行一次赋值操作(或称赋值运算).把常量3赋给变量a.也可以将一个表达式的值赋给一个变量. 赋值过程中的 ...

  2. 纯CSS3实现常见多种相册效果

    本文包含 1.CSS3中2D转换和3D转换的介绍. 2.在相册中的应用实例. CSS3中的转换效果和动画效果十分强大好用,可以实现一些常见的动态效果. 如此一来,CSS3便可以代替许多jQuery的功 ...

  3. C语言数据结构-创建链表的四种方法

    结点类型: typedef int datatype; typedef struct NODE{ datatype data; struct NODE *next; }Node,*LinkList; ...

  4. Cloud Engine

    Cloud Engine:大杀器如何炼成   郑昀 创建于2016/6/18 最后更新于2016/6/19 点击查看我的<如何从零搭建一个技术平台>,这是一个系列.转载时请注明“转载自旁观 ...

  5. openssl生成pem,密钥证书的创建

    使用OpenSSL生成证书 首先得安装OpenSSL软件包openssl,安装了这个软件包之后,我们可以做这些事情: o Creation of RSA, DH and DSA Key Paramet ...

  6. Ch05 视图模型

    5.1  什么是视图模型 5.1.1  在线商店示例 5.1.2  建立视图模型 5.1.3  交付表现模型 5.1.4  ViewData.Model 5.2  表现用户输入 5.2.1  设计(输 ...

  7. @produces在spring mvc中是什么意思

    @RequestMapping(value = "/produces", produces = "application/json"):表示将功能处理方法将生产 ...

  8. 基于visual Studio2013解决面试题之1402选择排序

     题目

  9. 基于visual Studio2013解决C语言竞赛题之1033数字交换

          题目 解决代码及点评 /* 功能:将一个一维数组中的偶数依次交换.例如有8个元素, 若其中第1.4.5三元素是偶数时应按下图交换. 例子: a[]={2,3,1,6 ...

  10. Server-side Sessions with Redis | Flask (A Python Microframework)

    Server-side Sessions with Redis | Flask (A Python Microframework) Server-side Sessions with Redis By ...