Delphi in WebBrowser automatic Form fill template

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//Radio Box
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//multiple lines of text
Begin
Value: = ' textarea ';
End
End
else if SUCCEEDED (Dispatch.queryinterface (ihtmloptionelement,htmloptionelement)) Then
Begin
With Htmloptionelement do//drop-down option
Begin
Processing
End
End
else if SUCCEEDED (Dispatch.queryinterface (ihtmlformelement,htmlformelement)) Then
Begin
With Htmlformelement do//form
Begin
Processing
End
End
else if SUCCEEDED (Dispatch.queryinterface (ihtmloptionbuttonelement,htmloptionbuttonelement)) Then
Begin
Unknown
Processing
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//has a frame
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 (FrameWindow.document.all);
End
End;
End
End
End
End;
End
End
Procedure Tmainfrm.btntestclick (Sender:tobject);
Begin
Fillieform (Edurl.text);
End
End.

http://blog.csdn.net/iseekcode/article/details/4708400

Delphi in WebBrowser automatic Form fill template

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.