Lazarus

Programming => General => Topic started by: sporex on March 04, 2021, 03:17:55 pm

Title: TStringList functionality for Integer types
Post by: sporex on March 04, 2021, 03:17:55 pm
After exploring the usefulness of TStringList, especially for LOG files of limited size I am wondering whether a similar class exists for Integer types or even for Records?
In particular I am looking for a similar function like this one of TStringList for integers or even records:
TStringList.Delete(0);
TStringList.Add('XY');
which makes it very easy to implement a ring buffer.

Thx for advice
Title: Re: TStringList functionality for Integer types
Post by: Handoko on March 04, 2021, 04:00:35 pm
TStringList is for string, for non-string items you can try TList or TFPList.

Or maybe you should check it:
https://wiki.freepascal.org/Data_Structures,_Containers,_Collections
Title: Re: TStringList functionality for Integer types
Post by: wp on March 04, 2021, 04:21:41 pm
In unit "integerlist", package LazUtils, there is a TIntegerList. It specializes TFPGList and thus has all the methods of it:


Example:
Code: Pascal  [Select][+][-]
  1. uses
  2.   IntegerList;
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. var
  6.   L: TIntegerList;
  7. begin
  8.   L := TIntegerList.Create;
  9.   try
  10.     L.Add(1);
  11.     L.Add(10*L[0]);
  12.     ShowMessage(IntToStr(L.Count));
  13.     L.Delete(0);
  14.     ShowMessage(IntToStr(L[0]));
  15.   finally
  16.      L.Free;
  17.   end;
  18. end;
Title: Re: TStringList functionality for Integer types
Post by: ASBzone on March 04, 2021, 04:23:00 pm
Beyond TList, consider whether or not a Dynamic Array would be helpful for you:

https://wiki.freepascal.org/FPC_New_Features_3.2.0#Dynamic_Arrays_supported_by_Insert.28.29
Title: Re: TStringList functionality for Integer types
Post by: Handoko on March 04, 2021, 04:39:08 pm
That's great, I didn't know about it. That feature is very useful. Thank you for informing and thank you for adding the feature.
Title: Re: TStringList functionality for Integer types
Post by: sporex on March 04, 2021, 04:47:21 pm
This unit "integerlist", package LazUtils seems to be great.
Provides apparently all functionalities of TStringList.

Thx a lot
Title: Re: TStringList functionality for Integer types
Post by: wp on March 04, 2021, 06:06:39 pm
thank you for adding the feature.
This goes to Juha.
Title: Re: TStringList functionality for Integer types
Post by: Bart on March 04, 2021, 08:58:08 pm
which makes it very easy to implement a ring buffer.

There is TDeque in gdeque unit, which implements a generic double ended queue.

Bart
TinyPortal © 2005-2018