* * *

Author Topic: Bug in StringLists  (Read 356 times)

apexcol

  • New member
  • *
  • Posts: 21
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

  • Full Member
  • ***
  • Posts: 103
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: 2741
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

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus