Loading a multi-dimensional static array

This feels like poorly written written code, is there a better way?
[ D6, WinXPHome ]

-----------clip------------------
  ButtonArray: [1..7,1..5] of String;



  ButtonArray[1][1] := 'some text';
  ButtonArray[1][2] := 'some text';
  ButtonArray[1][3] := 'some text';
  ButtonArray[1][4] := 'some text';
  ButtonArray[1][5] := 'some text';

  ButtonArray[2][1] := 'some text';
  ButtonArray[2][2] := 'some text';
  ButtonArray[2][3] := 'some text';
  ButtonArray[2][4] := 'some text';
  ButtonArray[2][5] := 'some text';
  ...
-----------clip------------------

 I know I can load a single dimension array like this
    ButtonArray: array [1..5] of String = ('some text','some text','some text','some text','some text');

Is there a better way to load a multi-dimensional array?


Don
d32coderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

moorhouselondonCommented:
const
  maxi=7;
  maxj=5;

var
  buttonarray: array[1..maxi,1..maxj] of string;



for i:=1 to maxi do
  for j:=1 to maxj do
    buttonarray[i,j]:='some text';


0
moorhouselondonCommented:
doh:I'm not thinking

of course you want sometext to be different ecvery time, i would use a resource file then

loadstr(i+maxi*j);

the resource file would be numbered from 1.
0
d32coderAuthor Commented:
I'd rather not have the data in an external file.   It's smaller code but not really what I'm looking for.   I was hoping I could put multiple strings into a single assignment as in the one dimensional array assignment in my example.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

d32coderAuthor Commented:
Now I'm not thinking, you said a resource, not a data file.  
That's probably a good idea.  
Let's see what other experts have to say.

Don
0
moorhouselondonCommented:
It depends what kind of strings you have.  In a program I'm writing at the moment, I construct the bit you put into brackets

('sometext','sometext' etc)

into an Excel file and do an Include at the declaration for the initial values, so it looks like this

   ButtonArray: array [1..5] of String = ('
{$INCLUDE progdata.csv}
');

...so that's another way.

If you are writing a multi-language program then you will want all of the language info in separate files.

0
Wim ten BrinkSelf-employed developerCommented:
var
  ButtonArray: array [1..5, 1..5] of String = (
    ('some text1A','some text2A','some text3A','some text4A','some text5A'),
    ('some text1B','some text2B','some text3B','some text4B','some text5B'),
    ('some text1C','some text2C','some text3C','some text4C','some text5C'),
    ('some text1D','some text2D','some text3D','some text4D','some text5D'),
    ('some text1E','some text2E','some text3E','some text4E','some text5E')
  );

However, if you need to fill it with data from a file or other source then you have no other option than to fill it field by field. (for I... for J... ButtonArray[I,J] :=...)
If it is a file of shortstrings then it is possible to write the whole array to file as a single block of data, though. Something like:

type
  TButtonArray: array [1..5, 1..5] of shortstring;
var
  ButtonArray: TButtonArray;
  ButtonFile: file of TButtonArray;
begin
  AssignFile(ButtonFile, 'Whatever.dat');
  Reset(ButtonFile);
  Read(ButtonFile, ButtonArray);
  CloseFile(ButtonFile);
end;

but this ONLY works for simple datatypes like integers, doubles, booleans and shortstrings. Any type that is pointer-based (normal strings, PChar's, classes) cannot be written to file like this. Furthermore, this code is incompatible with Delphi 8.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
d32coderAuthor Commented:
I split the points.  
Alex had the solution I was looking for; nested parentheses.  
I will use Moorhouse's idea on loading it into a resource file for this project.  
Thanks to both of you.

Don
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.