home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0215_Re: Array Indexes.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-04  |  987 b   |  37 lines

  1. {
  2. > I have been meaning to find out how one could get the lowest and highest
  3. > index values of a multidimensional array.
  4. >
  5. > I mean, say you have an array like this
  6. >
  7. >         MyArray : Arra[1..25, 5..9, 3..7] Of Something;
  8. >
  9. > Now, If I had to deal with it in a different unit, how would I find out how
  10. > big each dimension is?
  11.  
  12. Contrary to popular opinion, Basri, it's easy enough to determine the
  13. low and high indexes of a Pascal array: You use the Low and High
  14. functions! Here's a wee console app to show how it works.
  15.  
  16. program Project1;
  17.  
  18. uses
  19.   SysUtils;
  20.  
  21. {$APPTYPE CONSOLE}
  22.  
  23. var
  24.   MyArray: array[1..25, 5..9, 3..7] of Integer;
  25.   I1L, I1H, I2L, I2H, I3L, I3H: Integer;
  26. begin
  27.   I1L := low(MyArray);
  28.   I1H := high(MyArray);
  29.   I2L := low(MyArray[I1L]);
  30.   I2H := high(MyArray[I1L]);
  31.   I3L := low(MyArray[I1L][I2L]);
  32.   I3H := high(MyArray[I1L][I2L]);
  33.   Writeln(Format('[%d..%d, %d..%d, %d..%d]',
  34.     [I1L, I1H, I2L, I2H, I3L, I3H]));
  35.   Readln;
  36. end.
  37.