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: