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.