Delphi 子界类型定义
//整数,字符(ASCII码),有序类型
Const
x = 7;
y = 20;
a = -3;
type
TColors = ( red, green, blue, yellow);
num = x - a .. y;
ten = -5..10;
hundred = 100 -x .. 1000 -y;
UpperCase = 'A'..'F';
LowerCase = 'a' .. 'z';
colors = green..yellow;
子界
//定义 type Ten = 1..10; OverHundred = 100..1000; Uppercase = 'A'..'Z'; //TMonth = Jan..Dec;
//应用 var UppLetter: UpperCase; begin UppLetter := 'F';
//判断是否属于子界范围 var i: Integer; begin i := 1; if i in [0..10] then ShowMessage('i 大于0、小于10'); end;
//根据枚举定义子界 type TColors = (Red,Blue,Green,Yellow,Orange,Purple,White,Black); TMyColors = Blue..Yellow; var MyColor: TMyColors; begin MyColor := Blue; ShowMessage(IntToStr(Ord(MyColor))); //1 end;
//遍历子界 var character: 'a' .. 'z'; s: string; begin for character in [Low(character) .. High(character)] do begin s := s + character; end; ShowMessage(s); //abcdefghijklmnopqrstuvwxyz end;
来自万一老师
子界
//定义 type Ten = 1..10; OverHundred = 100..1000; Uppercase = 'A'..'Z'; //TMonth = Jan..Dec;
//应用 var UppLetter: UpperCase; begin UppLetter := 'F';
//判断是否属于子界范围 var i: Integer; begin i := 1; if i in [0..10] then ShowMessage('i 大于0、小于10'); end;
//根据枚举定义子界 type TColors = (Red,Blue,Green,Yellow,Orange,Purple,White,Black); TMyColors = Blue..Yellow; var MyColor: TMyColors; begin MyColor := Blue; ShowMessage(IntToStr(Ord(MyColor))); //1 end;
//遍历子界 var character: 'a' .. 'z'; s: string; begin for character in [Low(character) .. High(character)] do begin s := s + character; end; ShowMessage(s); //abcdefghijklmnopqrstuvwxyz end;