Recent

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

sporex

  • New Member
  • *
  • Posts: 39
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: 5131
  • 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: 11858
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;

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • 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.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • 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: 39
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: 11858
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.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • 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