Recent

Author Topic: 2 dimensional dynamic array  (Read 2663 times)

segfault

  • Full Member
  • ***
  • Posts: 107
2 dimensional dynamic array
« on: November 26, 2017, 03:44:40 pm »
I have a 'dynamic' table of values which I want to implement using a 2 dimensional dynamic array. The number of rows is fixed but the number of columns varies, so is it possible to increase the columns when the program is running?

i.e.  there are 107 rows, so I would initialise the array using 'setlength(X, 107, 1). How do I increase the number of columns by 1? For example if I want to add a column to the 50th row can I do this using 'setlength'? if so, how?

I could use one dimensional dynamic arrays but I would have to declare 107 of them.

Thanks.

FTurtle

  • Sr. Member
  • ****
  • Posts: 292
Re: 2 dimensional dynamic array
« Reply #1 on: November 26, 2017, 04:12:37 pm »
I have a 'dynamic' table of values which I want to implement using a 2 dimensional dynamic array. The number of rows is fixed but the number of columns varies, so is it possible to increase the columns when the program is running?

Yes, certainly.
See the example:
http://wiki.lazarus.freepascal.org/Example:_Multidimensional_dynamic_array

segfault

  • Full Member
  • ***
  • Posts: 107
Re: 2 dimensional dynamic array
« Reply #2 on: November 26, 2017, 04:27:43 pm »
Thanks! Just what I was looking for.

 

TinyPortal © 2005-2018