有如下数组,我想把每个月的天数分别赋值给各个元素,除了一个个赋值以外,请问有没有别的方法呢,比如类似C语言那样:a[12]={31,28,31,.....30},一个个赋值太繁琐了,谢谢各位!
var a:array[1..12] of integer; 

解决方案 »

  1.   


    const
      a : array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
      

  2.   


    也是可以修改的, 方法特殊点:
    const
      a : array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    begin
      PInteger(@a[1])^ := 1;
      PInteger(@a[12])^ := 12;
      ShowMessage(IntToStr(a[1]));
      ShowMessage(IntToStr(a[12]));
    end;
      

  3.   

    delphi的这个设计实在是太糟糕了,应该把常量数组链接到只读区去,想写入直接挂掉才对
      

  4.   

    这样确实有点问题,const 
      S: Integer = 3;
      Pinteger(@S)^ := 43;
      ShowMessage(IntToStr(S)); 结果是43我一直以为这样只是可读的, 特色写了个C++测试了下#include <iostream>
    using namespace std;
    int main(void)
    {
        const int s = 3;
        *(int*) &s = 43;
        cout<<s<<endl;
        return 0;
    }C++里结果还是3, 如果把CONST 去掉,则修改成功了
      

  5.   

    感谢一楼及其他楼主的帮忙,thank you so much!