2.常量
2.1.普通常量
仅仅下面类型可以被定义为常量
Ordinal类型
Set类型
指针类型 (but the only allowed value is Nil).
real类型
Char,
String
下面是定义的类型
Const
e = 2.7182818; { Real type constant. }
a = 2; { Ordinal (Integer) type constant. }
c = ’4’; { Character type constant. }
s = ’This is a constant string’; {String type constant.}
sc = chr(32)
ls = SizeOf(Longint);
P = Nil;
Ss = [1,2];
常量定义后是不能被赋值的,所以:
s := ’some other string’;
这样编译器是会报错的。
2.2.资源字符串
resourcestring
Part1 = ’First part of a long string.’;
Part2 = ’Second part of a long string.’;
Sentence = Part1+’ ’+Part2;
看下面代码:
resourcestring
Yes = ’Yes.’;
No = ’No.’;
Var
YesNo : Array[Boolean] of string = (No,Yes);
B : Boolean;
begin
Writeln(YesNo[B]);
end.