Delphi develops and modifies and submits Web form content

Source: Internet
Author: User

The program code mainly uses the WebBrowser control to modify and extract the webpage form content. The FillSelectForm function is used to modify the content of the Selection box. The following is the implementation function code:

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: Export webbrowser.doc ument 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;

 

 

 

 

The SubmitForm function implements form submission. The following is the code for implementing the function program:

 

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: Export webbrowser.doc ument 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.tar get: = '';

 

 

 

Hform. submit;

 

 

 

Result: = True;

 

 

 

Break;

 

 

 

End;

 

 

 

End;

 

 

 

End;

 

 

 

End;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The SubmitForm function implements form submission. The following is the code for implementing the function program:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.