(1)枚举类型
定义:type 枚举类型标识符=(标识符1,标识符2,…,标识符n)
枚举元素只能是标识符; 定义枚举类型时列出的所有枚举元素构成了这种枚举类型的值域(取值范围)。例如下列类型定义是合法的:
type
days=(sun,mon,tue,wed,thu,fri,sat);
colors=(red,yellow,blue,white,black,green);
应用实例-例:判断当前的颜色是什么。
type
TColors = (Red, Green, Blue);
procedure TForm1.Button1Click(Sender: TObject);
var
Colors: TColors;
begin
case Colors of
Red: begin
ShowMessage('红色');
end;
Green: begin
ShowMessage('绿色');
end;
Blue: begin
ShowMessage('蓝色');
end;
end;
end;
(2)子界类型
定义:type 子界类型标识符=常量1..常量2
常量1称为子界的下界,常量2称为子界的上界;所谓的上界也就是开始的边界,而下界就是结束的边界
应用举例-例:判断当前是周几
procedure TForm1.Button1Click(Sender: TObject);
var
Week: 1 .. 7;
begin
case Week of
1:
ShowMessage('周一');
2:
ShowMessage('周二');
3:
ShowMessage('周三');
4:
ShowMessage('周四');
5:
ShowMessage('周五');
6:
ShowMessage('周六');
7:
ShowMessage('周日');
else begin ShowMessage('非法')
end;
(3)集合
定义: set of 基类型;
function IsContainCharacter(Character: Char): Boolean;
var
Chars: set of 'A' .. 'Z';
begin
Result := Character in Chars;
end;
begin
try
Writeln(IsContainCharacter('B'));
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
标签:begin,end,数据类型,复合,枚举,ShowMessage,标识符,子界
From: https://www.cnblogs.com/DQ-MINE/p/17123278.html