Recent

Author Topic: TStringList functionality for Integer types  (Read 669 times)

sporex

  • New Member
  • *
  • Posts: 12
TStringList functionality for Integer types
« 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

Handoko

  • Hero Member
  • *****
  • Posts: 4158
  • My goal: build my own game engine using Lazarus
Re: TStringList functionality for Integer types
« Reply #1 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

wp

  • Hero Member
  • *****
  • Posts: 8291
Re: TStringList functionality for Integer types
« Reply #2 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;
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

ASBzone

  • Hero Member
  • *****
  • Posts: 614
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: TStringList functionality for Integer types
« Reply #3 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
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.0.13 r64843 / FPC v3.2.1-r49055 (via FpcUpDeluxe) -- Windows 64-bit install w/Win32 and Linux/Arm cross-compiles
Primary System: Windows 10 Pro x64, Version 2009 (Build 19042)
Other Systems: Windows 10 Pro x64, Version 2009 (Build 19042) or greater

Handoko

  • Hero Member
  • *****
  • Posts: 4158
  • My goal: build my own game engine using Lazarus
Re: TStringList functionality for Integer types
« Reply #4 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.

sporex

  • New Member
  • *
  • Posts: 12
Re: TStringList functionality for Integer types
« Reply #5 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

wp

  • Hero Member
  • *****
  • Posts: 8291
Re: TStringList functionality for Integer types
« Reply #6 on: March 04, 2021, 06:06:39 pm »
thank you for adding the feature.
This goes to Juha.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Bart

  • Hero Member
  • *****
  • Posts: 4225
    • Bart en Mariska's Webstek
Re: TStringList functionality for Integer types
« Reply #7 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