怎么樣定義一個常量的二維數組?


我有一批樣本數據,適合存儲成二維數組(Integer)的形式。

為了提高程序的可修改性,我希望把這批數據存放在一個獨立的Unit里面,寫成常量的二維數組存放形式。這個Unit該怎么寫呢?

unit SinSampleUnit;

interface

implementation

1.這個二維數組該放在什么地方?

2.常量的二位數組是怎么定義的?

3.我要在Unit中直接寫入數組元素(0.5, 1)的時候,語句是怎樣的?

7 个解决方案

#1


interface

  const a:array[0..3] of integer = (324, 54353, 5435, 5435);
  //在這里只有USES這個單元都能訪問
implementation
  //在這里只有本單元的下面能訪問
end;

#2


如果是二維數組,是怎么賦值的?給個語句例子?

#3


const DayList: array[0..6,1..4] of SmallInt
                   =((1,  5,11,1),
                     (6, 10,11,1),
                     (11,15,17,2),
                     (16,20,23,3),
                     (21,25,23,3),
                     (26,31,11,1),
                     (99,99,17,2)
                    );

#4


定義const a:array[0..2,0..2] of integer = (324, 54353, 5435, 5435,23,343);
a[0,2]:=234;

#5


unit SinSampleUnit;

interface

uses
  Graphics;
const
  sinSampleNo = 20; //the number of sin funcion's sample
  PI = 3.1415926535897932384626433832795;
type
  TSinSample = array[0..sinSampleNo -1, 0..1] of double;
  SinSample: TSinSample = ((-1.0*PI, 0),
                           (-0.9*PI, -0.30901699437494742410229341718282),
                           (-0.8*PI, -0.58778525229247312916870595463907),
                           (-0.7*PI, -0.80901699437494742410229341718282),
                           (-0.6*PI, -0.95105651629515357211643933337938),
                           (-0.5*PI, -1.00000000000000000000000000000000),
                           (-0.4*PI, -0.95105651629515357211643933337938),
                           (-0.3*PI, -0.80901699437494742410229341718282),
                           (-0.2*PI, -0.58778525229247312916870595463907),
                           (-0.1*PI, -0.30901699437494742410229341718282),
                           (0, 0),
                           (0.1*PI, 0.30901699437494742410229341718282),
                           (0.2*PI, 0.58778525229247312916870595463907),
                           (0.3*PI, 0.80901699437494742410229341718282),
                           (0.4*PI, 0.95105651629515357211643933337938),
                           (0.5*PI, 1.00000000000000000000000000000000);
                           (0.6*PI, 0.30901699437494742410229341718282),
                           (0.7*PI, 0.58778525229247312916870595463907),
                           (0.8*PI, 0.80901699437494742410229341718282),
                           (0.9*PI, 0.95105651629515357211643933337938),
                           (1.0*PI, 0));

implementation

end.
可是為什么這個完整的單元在編譯時出現錯誤:?
 '=' expected but ':' found

光標停在SinSample:
的冒號后面。

#6


ding

#7


const SinSample: TSinSample = ((-1.0*PI, 0),...)
↑挿入"const"常量定義説明。

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com