Recent

Author Topic: [Solved] Integer Dynamic Array  (Read 1544 times)

jcmontherock

  • Sr. Member
  • ****
  • Posts: 363
[Solved] Integer Dynamic Array
« on: August 27, 2025, 04:30:50 pm »
Is "TIntegerArray" a dynamic array ?
« Last Edit: August 27, 2025, 05:47:36 pm by jcmontherock »
Windows 11 UTF8-64 - Lazarus 4.8-64 - FPC 3.2.2

CM630

  • Hero Member
  • *****
  • Posts: 1759
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Integer Dynamic Array
« Reply #1 on: August 27, 2025, 04:34:50 pm »
Type TIntegerArray anywhere in your code, click it and press Alt+Up_Arrow.
Then you will get:
Code: Pascal  [Select][+][-]
  1. {$ifdef CPU16}
  2.        IntegerArray  = array[0..(32768 div SizeOf(Integer))-2] of Integer;
  3. {$else CPU16}
  4.        IntegerArray  = array[0..$effffff] of Integer;
  5. {$endif CPU16}
  6.        TIntegerArray = IntegerArray;
Лазар 4,8 32 bit (sometimes 64 bit); FPC3,2,2

cdbc

  • Hero Member
  • *****
  • Posts: 2921
    • http://www.cdbc.dk
Re: Integer Dynamic Array
« Reply #2 on: August 27, 2025, 04:36:10 pm »
Hi
NO
Code: Pascal  [Select][+][-]
  1. IntegerArray  = array[0..$effffff] of Integer;
Regards Benny

eta: To allocate it dynamically, you're meant to do so via
Code: Pascal  [Select][+][-]
  1. PIntegerArray = ^IntegerArray;
The reason it's such a big range, is to /not/ run into "Index out of bounds" errors. (which you could if you defined it like: intarry = array[0..0] of integer;)
« Last Edit: August 27, 2025, 04:41:39 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

jcmontherock

  • Sr. Member
  • ****
  • Posts: 363
Re: Integer Dynamic Array
« Reply #3 on: August 27, 2025, 05:45:52 pm »
So, I works for me if I define it like this:
Code: Pascal  [Select][+][-]
  1. Type
  2. TintArray = Array of Integer;
  3. ...
  4. private
  5. IntArray: TIntArray;
  6. // IntArray: TIntegerArray; // this definition is not a dynamic array.
  7.  
Windows 11 UTF8-64 - Lazarus 4.8-64 - FPC 3.2.2

cdbc

  • Hero Member
  • *****
  • Posts: 2921
    • http://www.cdbc.dk
Re: [Solved] Integer Dynamic Array
« Reply #4 on: August 27, 2025, 06:15:09 pm »
Hi
If you want a dynamic array of integer (managed), then YES that would be the way to go...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Thaddy

  • Hero Member
  • *****
  • Posts: 19606
  • Glad to be alive.
Re: [Solved] Integer Dynamic Array
« Reply #5 on: August 27, 2025, 09:43:00 pm »
What you want is defined in the types unit: TIntegerDynArray.
« Last Edit: August 27, 2025, 09:45:20 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

H₂SO₄

  • Sr. Member
  • ****
  • Posts: 485
Re: [Solved] Integer Dynamic Array
« Reply #6 on: August 28, 2025, 08:10:19 am »
I consider this definition to be legacy cruft and usually just overshadow it with a proper dynamic array definition.
TStringArray  for example is exactly what you'd expect, so why not make things consistent with  TIntegerArray?:

Code: Pascal  [Select][+][-]
  1. program Example;
  2.  
  3. {$mode objfpc} // <-- Implicitly `uses` the objpas unit
  4.  
  5. uses
  6.   SomeOtherUnit;
  7.  
  8. // Here `TIntegerArray` = array[0..$EFFFFFF] of Integer
  9.  
  10. type
  11.   TIntegerArray = array of Integer;
  12.  
  13. // Here `TIntegerArray` = array of Integer
  14.  
  15. // Original definition can be accessed using `objpas.TIntegerArray`
  16.  
  17. begin
  18. end.

With the amount of legacy identifiers that FPC needs to support for compatibility's sake, it's a blessing that identifiers can be shadowed/redefined so easily.  :)

Thaddy

  • Hero Member
  • *****
  • Posts: 19606
  • Glad to be alive.
Re: [Solved] Integer Dynamic Array
« Reply #7 on: August 28, 2025, 10:41:51 am »
That would in this case be a breaking change, hence the types unit that is often overlooked.
Any "programmer" that knows only one programming language is not a programmer

 

TinyPortal © 2005-2018