Webbrowser automatic table filling template in Delphi

Source: Internet
Author: User

 

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 // Single Line Text
Begin
If (uppercase (Type _) = 'text') or (uppercase (Type _) = 'Password') then
Begin
Value: = 'text ';
End
Else if (uppercase (Type _) = 'checkbox') Then // check box
Begin
Checked: = true;
End
Else if (uppercase (Type _) = 'Radio ') Then // single response
Begin
Checked: = true;
End;
End;
End
Else if succeeded (dispatch. QueryInterface (ihtmlselectelement, htmlselectelement) then
Begin
With htmlselectelement do // drop-down box
Begin
Selectedindex: = 1;
End;
End
Else if succeeded (dispatch. QueryInterface (ihtmltextareaelement, htmltextareaelement) then
Begin
With htmltextareaelement do // multiline text
Begin
Value: = 'textea ';
End;
End
Else if succeeded (dispatch. QueryInterface (ihtmloptionelement, htmloptionelement) then
Begin
With htmloptionelement do // drop-down list
Begin
// Process
End;
End
Else if succeeded (dispatch. QueryInterface (ihtmlformelement, htmlformelement) then
Begin
With htmlformelement do // form
Begin
// Process
End;
End
Else if succeeded (dispatch. QueryInterface (ihtmloptionbuttonelement, htmloptionbuttonelement) then
Begin
// Unknown
// Process
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 // No Frame
Begin
Elementcollection: = htmldocument. get_all;
Dowithhtmlelement (elementcollection );
End
Else // framework
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(framemediaworkflow Doc ument. All );
End;
End;
End;
End;
End;
End;
End;
End;
Procedure tmainfrm. btntestclick (Sender: tobject );
Begin
Fillieform (edurl. Text );
End;
End.

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.