Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-04

TDOMNodeList.GetItem

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexander Todorov
Hello,
as far as I tested TDOMNodeList.GetItem is not working correctly.
--------- original ---------------
function TDOMNodeList.GetItem(index: LongWord): TDOMNode;
var
  child: TDOMNode;
begin
  Result := nil;
  child := node.FirstChild;
  while Assigned(child) do
  begin
    if index = 0 then
    begin
      Result := child;
      break;
    end;
    if (not UseFilter) or (child.NodeName = filter) then
      Dec(index);
    child := child.NextSibling;
  end;
end;
-------------------- end original --------------------------------------
This is not checking the filter value if index is 0 /GetItem(0)/. And
what about negative inices? It should be changed like this :
------------------ change like this ----------------------
function TDOMNodeList.GetItem(index: LongWord): TnDOMElement;
var
  child: TDOMNode;
begin
  Result := nil;
  if index < 0 then
    exit;
  child := node.FirstChild;
  while Assigned(child) do
  begin
    if ((index = 0) and (not UseFilter)) or
       ((index = 0) and (UseFilter) and (child.NodeName = filter)) then
       begin
         Result := TnDOMElement(child);
         break;
       end;
    if (not UseFilter) or (child.NodeName = filter) then
      Dec(index);
    child := child.NextSibling;
  end;
end;
---------- end change ----------------------------

Your comments please.

Reply by email