怎么样定义一个常量的二维数组?


我有一批样本数据,适合存储成二维数组(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"常量定義説明。

注意!

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



 
  © 2014-2022 ITdaan.com