delphi开发修改并提交Web表单内容

来源:互联网 发布:米思米销售面试知乎 编辑:程序博客网 时间:2024/05/17 00:13

程序代码主要是通过WebBrowser控件来实现修改并提网页表单内容,FillSelectForm函数是实现修改选择框的内容,以下是实现函数程序代码:

function TForm1.FillSelectForm(WebBrowser: TWebBrowser; FieldName: string; Value: integer): Boolean;

var

  i, j: Integer;

  FormItem: Variant;

  hform:IHTMLFormelement;

  hdoc:ihtmldocument2;

  hall:ihtmlelementcollection;

  Hinput:IHTMLinputelement;

  Hselect:IHTMLSelectElement;

  hlen,tmploop:integer;

  vk:oleVariant;

  dispatch:IDispatch;

begin

  Result := False;

  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then

  begin

    Exit;

  end;

 

 

   if Assigned(WebBrowser) then

   begin

    hdoc:=WebBrowser.document as ihtmldocument2;

    hall :=hdoc.get_all;

    hlen := hall.get_length;

    for tmploop:=0 to hlen-1 do

    begin

      vk := tmploop;

      dispatch := hall.item(vk,0);

      if succeeded(Dispatch.QueryInterface(IHTMLSelectElement,Hselect)) then

      begin

        if (lowercase(Hselect.name)='xingzuo') then

        begin

            Hselect.selectedIndex := Value;

            Result := True;

        end;

      end;

    end;

   end;

end;

SubmitForm函数是实现提交表单处理,以下是实现函数程序代码:

SubmitForm函数是实现提交表单处理,以下是实现函数程序代码:

function TForm1.SubmitForm(WebBrowser: TWebBrowser;

  FormName: string): Boolean;

var

  i, j,k: Integer;

  FormItem: Variant;

  hform:IHTMLFormelement;

  hdoc:ihtmldocument2;

  hall:ihtmlelementcollection;

  Hinput:IHTMLinputelement;

  Hselect:IHTMLSelectElement;

  hlen,tmploop:integer;

  vk:oleVariant;

  dispatch:IDispatch;

  iw:IWebbrowser2;

begin

  Result := False;

  k:=0;

  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then

  begin

    Exit;

  end;

   if Assigned(WebBrowser) then 

   begin

    hdoc:=WebBrowser.document as ihtmldocument2;

    hall :=hdoc.get_all;

    hlen := hall.get_length;

    for tmploop:=0 to hlen-1 do

    begin

      vk := tmploop;

      dispatch := hall.item(vk,0);

      if succeeded(Dispatch.QueryInterface(IHTMLFormelement,hform)) and (lowercase(hform.name)='xingzuoday') then

      begin

        hform.target :='';

        hform.submit;

        Result := True;

        Break;

      end;

    end;

   end;

end;

原创粉丝点击