[fpc-devel] TDOMNodeList.GetItem

Alexander Todorov alexx.todorov at gmail.com
Thu Apr 13 09:26:52 CEST 2006


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.



More information about the fpc-devel mailing list