以前的笔记或摘录:Get Listbox Items from a TWebBrowser Document?
来源:互联网 发布:sql exists的含义 编辑:程序博客网 时间:2024/06/11 23:53
//Add MSHTML to your uses clause
//Add a TWebBrowser
//Add two buttons
//Add a ComboBox
//////////////////////////////////////////////////////////////////////////////
function IsSelectElement(eleElement: IHTMLElement): Boolean;
//////////////////////////////////////////////////////////////////////////////
var
selElement: IHTMLSelectElement;
begin
Result := False;
try
selElement := eleElement as IHTMLSelectElement;
except
Exit;
end;
Result := True;
end;
///////////////////////////////////////////////////////////////////////////////
procedure GetListBoxOptions(Web1: TWebBrowser;
strListBoxName: string;
intInstance: Integer;
tslLines: TStrings;
out intSelected: Integer);
///////////////////////////////////////////////////////////////////////////////
var
eleChild: IHTMLElement;
eleElement: IHTMLElement;
colGrandParents: IHTMLElementCollection;
colParents: IHTMLElementCollection;
selElement: IHTMLSelectElement;
intCount: Integer;
intG: Integer;
intGMax: Integer;
intP: Integer;
intPMax: Integer;
Document: IHTMLDocument2;
begin
tslLines.Clear;
intSelected := -1;
intCount := -1;
//Magic declarations
Document := Web1.Document as IHTMLDocument2;
if Document = nil then Exit;
colGrandParents := Document.All;
if colGrandParents = nil then Exit;
intGMax := colGrandParents.Length - 1;
for intG := 0 to intGMax do
begin
eleElement := colGrandParents.Item(intG, '') as IHTMLElement;
if IsSelectElement(eleElement) then
begin
selElement := eleElement as IHTMLSelectElement;
if selElement.Name = strListBoxName then
begin
//Found a list box with the correct name.
Inc(intCount);
if intCount = intInstance then
begin
//Found the instance with the correct name.
intSelected := selElement.selectedIndex;
colParents := eleElement.children as IHTMLElementCollection;
intPMax := colParents.Length - 1;
for intP := 0 to intPMax do
begin
eleChild := colParents.Item(intP, '') as IHTMLElement;
tslLines.Add(eleChild.InnerText);
end;
end;
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.swissdelphicenter.ch/torry');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
intSelected: Integer;
begin
ComboBox1.Text := '';
GetListBoxOptions(WebBrowser1, 'select', 0, ComboBox1.Items, intSelected);
if intSelected > -1 then
begin
ComboBox1.Text := ComboBox1.Items[intSelected];
end;
end;
- 以前的笔记或摘录:Get Listbox Items from a TWebBrowser Document?
- 以前的笔记或摘录:delphi IDE的快捷键
- 以前的笔记或摘录:delphi关闭XP防火墙
- 以前的笔记或摘录:idsmpt身份认证相关
- 以前的笔记或摘录:WebBrowser中显示源代码
- 以前的笔记或摘录: 存储网页为HTM
- 以前的笔记或摘录:存储网页为JPG
- 以前的笔记或摘录:保存网页中的所有图片
- Get the Url of a Hyperlink when the Mouse moves Over a TWebBrowser Document
- 以前的笔记或摘录:在TEmbeddedWB中使用自己的右键菜单
- 以前的笔记或摘录:通过Shellexecute发送带附件的邮件
- ...append HTML Text to a TWebbrowser Document?
- append HTML Text to a TWebbrowser Document?
- how to get internal items from a dialog created from wizard of VC2005
- How to Execute a JavaScript Code on a TWebBrowser Document
- #400 – 使用ItemsPanel 属性将WrapPanel 作为ListBox的显示面板(Using a WrapPanel as the Items Panel for a ListBox)
- sql--Delete repeated items from a table
- winform 两个listBox左右互移,支持多选或单选移动,移动时源listBox除移已除动的Items
- 以前的笔记或摘录:WebBrowser中显示源代码
- .NET2.0隐形的翅膀,正则表达式搜魂者
- C#文件读写IO操作 实例
- 个人空间岁末大回报活动12月15日获奖名单
- V$SESSION_LONGOPS
- 以前的笔记或摘录:Get Listbox Items from a TWebBrowser Document?
- SD2C大会流水帐
- 群联量产
- 用document.domain解决Ajax跨子域
- 以前的笔记或摘录:在TEmbeddedWB中使用自己的右键菜单
- typedef和typename关键字
- resin专业版性能调优总结
- 以前的笔记或摘录: 存储网页为HTM
- web services 中资源文件的路径问题