当前位置:编程文档 >> DELPHI >> Delphi自动填写IE输入框演示源码
首页

Delphi自动填写IE输入框演示源码

所属类别:DELPHI
推荐指数:★★★★
文档人气:1
本周人气:1
发布日期:2008-9-15

//自动填写主要过程;
procedure TForm1.FillIEForm(aValidatecode: String; bPost: boolean);
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(IHTMLFormElement,HTMLFormElement))then
begin
with HTMLFormElement do//表单
begin
//处理
if bPost then
begin
HTMLFormElement.submit ;//提交所填写的窗体;
exit;
end;
end;
end
//如果是输入框;
else if Succeeded(Dispatch.QueryInterface(IHTMLInputElement,HTMLInputElement)) then
begin
With HTMLInputElement do//单行文本
begin
if (UpperCase(Type_)='TEXT') or (UpperCase(Type_)='PASSWORD') then//判断输入框类型;
begin
value:='luowenfu'; //输入名字;
if Name='Validatecode' then Value:=aValidatecode;
if Name='Passwd' then Value:='19820128'; //输入密码;
if Name='Passwd1' then Value:='19820128';
if Name='e_mail' then value:='luowenfu_1982@163.com';
if Name='OICQ' then Value:='282839896';
if Name='width' then Value:='40';
if Name='height' then Value:='40';
if Name='myface' then Value:='';
end
else if (UpperCase(Type_)='CHECKBOX') then//复选框
begin
checked:=true;
end
else if (UpperCase(Type_)='RADIO') then//单选框
begin
checked :=true;
end
else if (UpperCase(Type_)='FILE') then//选择路径;
begin
HTMLInputElement.defaultValue:='E:\LWen\Lwen作品\卡片\ExeFile\pic\cat1\3.bmp';
end;

end;
end
else if Succeeded(Dispatch.QueryInterface(IHTMLSelectElement,HTMLSelectElement)) then
begin
With HTMLSelectElement do//下拉框
begin
selectedIndex :=1;//默认选择第二个;
end;
end
else if Succeeded(Dispatch.QueryInterface(IHTMLTEXTAreaElement,HTMLTextAreaElement)) then
begin
with HTMLTextAreaElement do//多行文本
begin
value :='向别人学习!再教别人学习!!';
end;
end
else if Succeeded(Dispatch.QueryInterface(IHTMLOptionElement,HTMLOptionElement)) then
begin
with HTMLOptionElement do//下拉选项
begin
//处理
end;
end
else if SUCCEEDED(Dispatch.QueryInterface(IHTMLOptionButtonElement,HTMLOptionButtonElement))then
begin
//不明
//处理
end
else
//showmessage('other');
;
end;
end;
var
HTMLDocument:IHTMLDocument2;//可修改文档;
ElementCollection:IHTMLElementCollection;
Dispatch: IDispatch;
i,j:integer;
FrameWindow:IHTMLWindow2;//框架窗口;
Vi,Vj:OLEVariant;
HTMLFrameBase :IHTMLFrameBase ;
HTMLFrameElement:IHTMLFrameElement ;
HTMLIFrameElement:IHTMLIFrameElement;
begin
HTMLDocument:=IHTMLDocument2(WebBro1.Document);//指定要修改的文档;
if HTMLDocument<>nil then
begin
begin
if HTMLDocument.frames.length =0 then//如果是无框架
begin
ElementCollection:=HTMLDocument.Get_All;
DoWithHtmlElement(ElementCollection);//调用填写过程;
end
else//有框架
begin
//先填写当前页;
ElementCollection:=HTMLDocument.Get_All;
DoWithHtmlElement(ElementCollection);
//再填写框架页;
for j:=0 to HTMLDocument.frames.length -1 do
begin
Vj:=j;
Dispatch:=HTMLDocument.frames.item(Vj);
if Succeeded(Dispatch.QueryInterface(IHTMLWindow2,FrameWindow)) then
begin
DoWithHtmlElement(FrameWindow.document.all);//调用自动填写过程;
end;
End;
end;
end;
end;
end;
里面的有关HTML的接口声明请自行参考以下网站:
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/ifaces/inputelement/maxlength.asp

文档说明:

     

相关文档


读取评论列表……