Recent

Author Topic: Bug in StringLists  (Read 2894 times)

apexcol

  • Jr. Member
  • **
  • Posts: 54
Bug in StringLists
« on: August 11, 2017, 12:28:26 pm »
I have problems with TStringList...

Code: Pascal  [Select][+][-]
  1. procedure TotaliseByNames;
  2. var
  3.         SL : TStringList;
  4.         I1, I3 : integer;
  5.         vElement: TDOMElement;
  6.         vInputList: TDOMNodeList;
  7. begin   // vInputList is out of scope but is another TStringList
  8.         SL := TStringList.Create;
  9.         SL.Sorted := true;
  10.         for I1 := 0 to pred(vInputList.Count) do begin
  11.                 vElement := vInputList[I1];
  12.                 SL.Find(vElement['name'], I3);
  13.                 if I3 = -1 then  // does not exist then
  14.                         SL.AddObject(vElement['name'], vElement) // create the first
  15.                 else begin
  16.                         {some other code that modifies vElement with aritmethic operations...}
  17.                 end;
  18.         FAnotherList.Assign(SL);               
  19. end;
  20.  

on the Finding it breaks the program...

Also I tried with IndexOf and it shows a number like 8261232 instead of -1,
I checked the code inside and it has some things to fix, for example
in stringl.inc line 936 instead of Result:=Result+1; it must be inc(Result), and
on sorted list, the add or insert method ought to add it on the right place.

bytebites

  • Hero Member
  • *****
  • Posts: 717
Re: Bug in StringLists
« Reply #1 on: August 11, 2017, 01:48:21 pm »
Code: Pascal  [Select][+][-]
  1.                if SL.Find(vElement['name'], I3) then begin
  2.                         {some other code that modifies vElement with aritmethic operations...}
  3.                 end
  4.                 else
  5.                     SL.AddObject(vElement['name'], vElement)
  6.                

rvk

  • Hero Member
  • *****
  • Posts: 6760
Re: Bug in StringLists
« Reply #2 on: August 11, 2017, 02:33:49 pm »
Why open three posts/topics for this?

I answered here:
http://forum.lazarus.freepascal.org/index.php/topic,37880.msg255895.html

 

TinyPortal © 2005-2018