TWebBrowser控件 相关内容
来源:互联网 发布:winrar软件破解版 编辑:程序博客网 时间:2024/06/06 05:16
1、WebBrowser.OleObject.Document:
var
document: IHTMLDocument2;begin
document := WebBrowser.Document as IHTMLDocument2;
if Assigned(document) then
.
.
2、WebBrowser. OleObject. Document. All:
var
document: IHTMLDocument2;docAll: IHTMLElementCollection;
firstElement: IHTMLElement;
begin
document := WebBrowser.Document as IHTMLDocument2;
if Assigned(document) then
begin
docAll := document.all;
firstElement := docAll.Item(0,'');
3、WebBrowser.OleObject.Document.Forms:
var
htmlDoc: IHTMLDocument2;
allForms: IHTMLElementCollection;
firstForm: IHTMLFormElement;
begin
htmlDoc := WebBrowser.Document as IHTMLDocument2;
allForms := htmlDoc.Forms;
firstForm := allForms.Item(0,'') as IHTMLFormElement;
3.1、得到一个页面中form的数目:
function NumberOfForms(document: IHTMLDocument2): integer;
var
forms: IHTMLElementCollection;
begin
forms := document.Forms as IHTMLElementCollection;
result := forms.Length;
end;
3.2、通过form的数字序号取得form:
function GetFormByNumber(document: IHTMLDocument2;
formNumber: integer): IHTMLFormElement;
var
forms: IHTMLElementCollection;
begin
forms := document.Forms as IHTMLElementCollection;
if formNumber < forms.Length then
result := forms.Item(formNumber,'') as IHTMLFormElement
else
result := nil;
end;
3.3、取得某一form的名字:
var
firstForm: IHTMLFormElement;
document: IHTMLDocument2;
begin
document := WebBrowser.Document as IHTMLDocument2;
firstForm := GetFormByNumber(document,0);
if Assigned(firstForm) then
ShowMessage('Name of first form is ' + firstForm.Name)
else
ShowMessage('This page does not contain any forms');
3.4、通过form名字取得form:
function GetFormByName(document: IHTMLDocument2;
const formName: string): IHTMLFormElement;
var
forms: IHTMLElementCollection;
begin
forms := document.Forms as IHTMLElementCollection;
result := forms.Item(formName,'') as IHTMLFormElement
end;
3.5、List the names of all the fields on a form:
function GetFormFieldNames(fromForm: IHTMLFormElement): TStringList;
var
index: integer;
field: IHTMLElement;
input: IHTMLInputElement;
select: IHTMLSelectElement;
text: IHTMLTextAreaElement;
begin
result := TStringList.Create;
for index := 0 to fromForm.length do
begin
field := fromForm.Item(index,'') as IHTMLElement;
if Assigned(field) then
begin
if field.tagName = 'INPUT' then
begin
// Input field.
input := field as IHTMLInputElement;
result.Add(input.name);
end
else if field.tagName = 'SELECT' then
begin
// Select field.
select := field as IHTMLSelectElement;
result.Add(select.name);
end
else if field.tagName = 'TEXTAREA' then
begin
// TextArea field.
text := field as IHTMLTextAreaElement;
result.Add(text.name);
end;
end;
end;
end;
3.6、Get the value of a named field:
function GetFieldValue(fromForm: IHTMLFormElement;
const fieldName: string): string;
var
field: IHTMLElement;
inputField: IHTMLInputElement;
selectField: IHTMLSelectElement;
textField: IHTMLTextAreaElement;
begin
field := fromForm.Item(fieldName,'') as IHTMLElement;
if not Assigned(field) then
result := ''
else
begin
if field.tagName = 'INPUT' then
begin
inputField := field as IHTMLInputElement;
result := inputField.value
end
else if field.tagName = 'SELECT' then
begin
selectField := field as IHTMLSelectElement;
result := selectField.value
end
else if field.tagName = 'TEXTAREA' then
begin
textField := field as IHTMLTextAreaElement;
result := textField.value;
end;
end
end;
3.7、Set the value of a named field:
procedure SetFieldValue(theForm: IHTMLFormElement;
const fieldName: string; const newValue: string);
var
field: IHTMLElement;
inputField: IHTMLInputElement;
selectField: IHTMLSelectElement;
textField: IHTMLTextAreaElement;
begin
field := theForm.Item(fieldName,'') as IHTMLElement;
if Assigned(field) then
begin
if field.tagName = 'INPUT' then
begin
inputField := field as IHTMLInputElement;
inputField.value := newValue;
end
else if field.tagName = 'SELECT' then
begin
selectField := field as IHTMLSelectElement;
selectField.value := newValue;
end
else if field.tagName = 'TEXTAREA' then
begin
textField := field as IHTMLTextAreaElement;
textField.value := newValue;
end;
end;
end;
3.8、Submit the form:
procedure TMyForm.Button1Click(Sender: TObject);
var
document: IHTMLDocument2;
theForm: IHTMLFormElement;
index: integer;
begin
document := TWebBrowser.Document as IHTMLDocument2;
theForm := GetFormByNumber(document,0);
SetFieldValue(theForm,'name','Brian Cryer');
theForm.submit;
4、WebBrowser. OleObject. Document. Frames:
.Length 文档中的框架数目。 .Item(0) 第一个框架。 .Item(0).Document 第一个框架内的文档. .Item(0).Document.URL 第一个框 架的的URL。.
Document 相当于:
(WebBrowser.Document as IHTMLDocument2).Frames
例:得到关于作为IHTMLWindow2或IHTMLDocument2框架的信息:
var
document: IHTMLDocument2;
ole_index: OleVariant;
doc_all: IHTMLElementCollection;
frame_dispatch: IDispatch;
frame_win: IHTMLWindow2;
frame_doc: IHTMLDocument2;
begin
document := WebBrowser.Document as IHTMLDocument2;
ole_index := 0;
frame_dispatch := document.Frames.Item(ole_index);
if frame_dispatch <> nil then
begin
frame_win := frame_dispatch as IHTMLWindow2;
frame_doc := frame_win.document;
.
.
5、WebBrowser. OleObject. Document. Images:
文档内的图像数组。
.Length 文档中图像的数量。 .Item(0)第一个图像。 .Item(0).Src 第一个图像的地址。
6、WebBrowser. OleObject. Document. Links
表示所有链接的数组(像 "<a href...>"元素).
.Length 链接的数量 .Item(0) 第一个链接。 .Item(0).href 第一个链接的地址。 .Item(0).TagName 第一个链接的类型名称。 对于链接来讲TagName通常为 'A'.
Document 相当于:
var
htmlDoc: IHTMLDocument2;allLinks: IHTMLElementCollection;
firstLink: IHTMLElement;
url: String;
begin
htmlDoc := WebBrowser.Document as IHTMLDocument2;
allLinks := htmlDoc.Links;
firstLink := allLinks.Item(0,'') as IHTMLElement;
url := firstLink.toString;
- TWebBrowser控件 相关内容
- Twebbrowser控件如果写多线程
- 如何获取TWebBrowser控件的超级链接
- TWebBrowser控件与MSHTML库连接
- Delphi 中TWebBrowser的扩展控件TExWebBrowser
- TWebBrowser控件与MSHTML库连接
- Delphi下TWebBrowser控件的使用
- delphi中TWebBrowser控件增强版
- delphi中TWebBrowser控件常用实例集锦
- Delphi 中TWebBrowser的扩展控件TExWebBrowser
- TWebBrowser控件方法性性事件说明
- TWebBrowser控件使用指定IE版本显示网页
- dephi Twebbrowser控件运行使用指定IE浏览器版本
- 相关内容
- Android:Activity和Fragment交互、Fragment控件UI升级相关内容
- TWebBrowser编程
- TWebBrowser编程
- Delphi TWebBrowser
- 用javascript获取屏幕高度和宽度等信息
- 汽车通讯数据处理(CAN)
- pdf资料下载 编程
- leach分析1
- GDAL写PCIDISK(*.PIX)格式,用ERDAS读取出错的问题
- TWebBrowser控件 相关内容
- [应用架构] HQL 查询方式(传统方式和占位方式)
- setsid()
- android手机时间自动同步
- linux下程序前后台切换运行
- javascript正则表达式方法
- 单例模式
- weibo4android新浪微博认证失效报错401
- setup a fake ap with backtrack5