Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9192257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:52:43+00:00 2026-06-17T20:52:43+00:00

guys: I got a problem about how to get an IHTMLElementCollection obj which composed

  • 0

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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:52:44+00:00Added an answer on June 17, 2026 at 8:52 pm

    You could simply create your own container class, such as TList<IHTMLElement> or an array of IHTMLElements:

    type
      THTMLElements = array of IHTMLElement;
    
    function GetElementsByClassName(ADoc: IDispatch; const strClassName: string): THTMLElements;
    var
      vDocument: IHTMLDocument2;
      vElementsAll: IHTMLElementCollection;
      vElement: IHTMLElement;
      I, ElementCount: Integer;
    begin
      Result := nil;
      ElementCount := 0;
      if not Supports(ADoc, IHTMLDocument2, vDocument) then
        raise Exception.Create('Invalid HTML document');
      vElementsAll := vDocument.all;
      SetLength(Result, vElementsAll.length); // set length to max elements
      for I := 0 to vElementsAll.length - 1 do
        if Supports(vElementsAll.item(I, EmptyParam), IHTMLElement, vElement) then
          if SameText(vElement.className, strClassName) then
          begin
            Result[ElementCount] := vElement;
            Inc(ElementCount);
          end;
      SetLength(Result, ElementCount); // adjust Result length
    end;
    

    Usage:

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      WebBrowser1.Navigate('http://stackoverflow.com/questions/14535755/how-to-get-an-ihtmlelementcollection-obj-which-composed-of-several-ihtmlelements');
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Elements: THTMLElements;
      I: Integer;
    begin
      // show Tags information for SO page:
      Elements := GetElementsByClassName(WebBrowser1.Document, 'post-tag');
      ShowMessage(IntToStr(Length(Elements)));
      for I := 0 to Length(Elements) - 1 do
        Memo1.Lines.Add(Elements[I].innerHTML + ':' + Elements[I].getAttribute('href', 0));
    end;
    

    The main problem with returning the result as IHTMLElementCollection, is that IHTMLElementCollection is created internally by IHTMLDocument, and I could not find any way of creating a new instance of IHTMLElementCollection and adding references of the elements to it e.g.:

    vElementsRet := CoHTMLElementCollection.Create as IHTMLElementCollection
    

    will result Class not registered exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys i got a problem which is doing my head in, and was
I got a weird problem with my dojo app. It's simply about the scope
Hi guys got a wired problem (well I find it a wired problem :P)
Hey guys, got a problem with a question. Question : Write a declaration for
Hi guys Ive got a problem with item renderer.I have a data group that
Coding in VB.Net Hi guys I've got this problem where I'm trying to assign
Hey guys! Got a problem when I connect with a embedded device via bluetooth.
hey Guys i've got a weird problem. If i create a custom button inside
I got a problem about including a included file in PHP. Project functions(folder) has
Hey guys, I have a bit of a problem. I get values from textarea

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.