neslib / Neslib.Xml

Ultra Light-Weight XML Library for Delphi
Other
54 stars 14 forks source link

A bit strange code #3

Closed Alekcvp closed 4 years ago

Alekcvp commented 4 years ago

I have some doubts that this code does exactly what it should:

function TXmlDocument.GetDocumentElement: TXmlNode;
begin
  if (FRoot <> nil) then
  begin
    Result := FRoot.FirstChild;
    while (Result <> nil) do
    begin
      if (Result.NodeType = TXmlNodeType.Element) then
        Exit;
    end;
  end;
  Result.FNode := nil;
end;

Especially the part of it that is inside the while-loop...

neslib commented 4 years ago

Oops. You are right. I forgot to update Result to the next sibling inside the loop. Just pushed a fix for that. Thanks for pointing this out!