Recent

Author Topic: How to create multi-dimensional dynamic control arrays?  (Read 6132 times)

sniperton

  • New Member
  • *
  • Posts: 18
How to create multi-dimensional dynamic control arrays?
« on: April 21, 2011, 12:25:34 pm »
Hi all, I'm a hobby programmer with some little past experience in good old Turbo Pascal and Visual Basic, but a very green newbie after all.

I found this discussion (http://www.lazarus.freepascal.org/index.php/topic,8489.msg40976.html#msg40976) very helpful, but still I can't figure out how I could create and use dynamic multi-dimensional arrays. In VB it was possible 'to redim' the first dimension at least IIRC. Can I do the same with SetLength?

My practical problem is that I want to create and handle several child-forms (1st dimension) with different sets of controls on each (2nd dimension). I should read this particular 'application structure' from an application config file (that the user can modify).

Could anyone provide me with a short code example please?
Many thanks
 

tintinux

  • Sr. Member
  • ****
  • Posts: 378
    • Gestinux
Re: How to create multi-dimensional dynamic control arrays?
« Reply #1 on: April 21, 2011, 01:59:00 pm »
Hi

To have several dimensions, the simplest is to use another dynamic array as the base type. It is better, but not required, to define a type for the first dimension : this way you will be able to make procedures to handle one dimension item.

For example :

Code: [Select]
type
  TLines = array of string ;
  TGrid = array of TLines ;

var
  AGrid : TGrid ;

begin
  SetLength ( AGrid, 1, 1);
  AGrid[0,0] := 'Something' ;
end ;

Just check the exact order of dimensions, I'm not sure.


Regards
Tintinux




« Last Edit: April 21, 2011, 04:23:41 pm by tintinux »
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

sniperton

  • New Member
  • *
  • Posts: 18
Re: How to create multi-dimensional dynamic control arrays?
« Reply #2 on: April 21, 2011, 03:05:42 pm »
Hi Tintinux, many thanks for the quick reply. So if I understand correctly, I have to create a chain of embedded arrays (to put it so sluggishly), where, in the given example, one of the dimensions will account for strings, the other for TLines. I'll give it a try.

 

TinyPortal © 2005-2018