is there a way to iterate over IHTMLElementCollection?
such as
var
e : IHTMLLinkElement;
elementCollection:IH开发者_如何转开发TMLElementCollection;
begin
for e in elementCollection do
showmessage(e.caption);
end;
i know there is a property named _newEnum, however it is not supported in delphi as much as i could understand.
update: apperently links are IHTMLElement and not IHTMLLinkElement
for I := 0 to Pred(elementCollection.length) do
begin
e := elementCollection.item(I, EmptyParam) as IHTMLElement;
//...
end;
The code to use _newEnum looks like this. If you're sure you've only got link elements items in the collection, you could change the as IHTMLElement
part (and the elem value type) of the inner loop to as IHTMLAnchorElement
(IHTMLLinkElement appears to be something entirely different)
uses MSHTML, ActiveX;
var
collection:IHTMLElementCollection;
enum:IEnumVariant;
v:OleVariant;
u:IUnknown;
element:IHTMLElement;
begin
//...
enum:=collection._newEnum as IEnumVariant;
while enum.Next(1,v,u)=S_OK do
begin
elem:=u as IHTMLElement;
//...
end;
精彩评论