Search the Community
Showing results for tags 'dynamic'.
Found 2 results
-
Creating irregularly shaped multi-dim dynamic arrays
JohnLM posted a topic in Algorithms, Data Structures and Class Design
Is it possible to set variable size multi-dimentional arrays dynamically at runtime? Or, do I have to be clever about it in another way? My usual ways to create m-a's are the typical triangle shape, not irregularly shaped. I want to create the irregularly shaped, like the examples listed below. I have been playing around with run-time dynamic arrays via SetLength() and then realized I can't create them dynamically with different size Columns. I have been using for/next and repeat/until loops of various kinds to attempt to do the irregularly shapped arrays but when I come to create a new Row and reset the C to 1, the data is wiped or I get strange behavior, which leads me to realize this route is not possible, and that I have to do something really clever, maybe to simulate multi-dim dynamic arrays. I have a string list that I want to parse as values--text for strings, numbers for integers. The multi-dim array can look something like the following examples below: where s=string, n=number, r=row, c=column So, using ex 1, as I parse my string list, (a single column list), R is set to 1 for row 1, and C is set to 1, and as I parse through the list, I inc(C) for row 1, thus, ( 1 [n, n, n] ) When I create row 2, I inc(R), and is now row 2, thus ( 2 [n, n, n, n, n] ), . . ., and so on, for row 3, . . . etc. ex 1 ==== R | C - - - > ----------------- 1 [n, n, n] 2 [n, n, n, n, n] 3 [n, n] 4 [n, n, n, n] 5 [n] ex 2 ==== R | C - - - > ----------------------------------------- 1 [n, n, n, n, n, n, n, n, n, n, n, n, n] 2 [s, s, s] 3 [n, n] 4 [s, s, s, s, s, s, s, s] ex 3 ==== R | C - - - > -------------------------------------------------------------- 1 [s, s] 2 [s] 3 [s, s, s, s, s] 4 [s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s] 5 [s, s, s] 6 [n, n, n, n, n, n, n] -
I've written this piece of code ... type def_dip_value=record dip_val:word; dip_name:string; end; tdef_dip=record mask:word; name:string; number:byte; dip:array of def_dip_value; end; ... Everything goes fine, but when I try to declare some const like this... const my_dip:array [0..1] of tdef_dip=( (mask:$f;name:'name1';number:16;dip:[(dip_val:$2;dip_name:'name1'),(dip_val:$5;dip_name:'name2')]), (mask:$10;name:'name2';number:2;dip:[(dip_val:$10;dip_name:'name3'),(dip_val:$0;dip_name:'name4')]) ); ... Cannot compile, delphi fails with error 'Undeclared identifier: 'dip_val' I've tested the same code on Free Pascal and works fine, so, what I'm doing wrong? Any idea?