guys: I got a problem about “how to get an IHTMLElementCollection obj which composed of several IHTMLElements” in object-pascal programming , my codes below:
function TExDomUtils.GetElementsByClassName(vDoc:IHTMLDocument3; strClassName:string):IHTMLElementCollection;
var
vElementsAll : IHTMLElementCollection;
vElementsRet : IHTMLElementCollection;
vElement : IHTMLElement;
docTmp : IHTMLDocument2;
I ,J: Integer;
begin
J := 0;
vElementsAll := vDoc.getElementsByTagName('*');
for I:=0 to vElementsAll.length - 1 do
begin
vElement := vElementsAll.item(I,0) as IHTMLElement;
if vElement.getAttribute('class',0) = strClassName then
begin
// how to get an IHTMLElementCollection obj which composed of several IHTMLElements?
J := J + 1;
end;
end;
Result := vElementsRet;
end;
You could simply create your own container class, such as
TList<IHTMLElement>or anarray of IHTMLElements:Usage:
The main problem with returning the result as
IHTMLElementCollection, is thatIHTMLElementCollectionis created internally byIHTMLDocument, and I could not find any way of creating a new instance ofIHTMLElementCollectionand adding references of the elements to it e.g.:will result
Class not registeredexception.