Subrange types)Defines a subset of an ordered type. The ordered value of the subfield must have been defined in another ordered type. The index of the ordered value in the subfield is determined by the base class.
It is in the formLow... high. HereLowAndHighIs a constant expression of the same order type, andLowRatioHighSmall.
When defining a sub-sector type variable, the value assigned to the variable must be a value within the defined range of the sub-sector.
Let's give a detailed example.
1,CreateConsole Application;
2,Enter the following code. Pay attention to the notes.
Program project1; {$ apptype console} uses sysutils; const x = 50; y = 10; Type Scale = 2 * (x-y ).. (x + y) * 2; {constant expression} // scale = (x-y) * 2 .. (x + y) * 2; {this statement and the above low .. the high range is the same, but the comments will cause compilation errors. In any type declaration, if the equal sign (=) is followed by a left parentheses (), the compiler considers it to be an enumeration type. If the above declaration is not an enumeration, an error will occur, avoid declaring that it is not an enumeration type. The left parentheses appear after the equal sign} tcolors = (red, blue, green, yellow, orange, purple, white, black ); {enumeration} tmycolors = green .. white; {defines a subfield type, ranging from green to white in enumeration} {tmycolors includes green, yellow, orange, purple, white} tsomenumbers =-128 .. 127; {subfield type of number range} TCAPs = 'A '.. 'Z'; {subfield type of the character range} var somenum: 1 .. 500; {You can also directly define the subinterface type variable} mycolors: tmycolors; somenumbers: tsomenumbers; caps: TCAPs; letter: Char; begin // caps: = 'E '; {this sentence will cause the compilation error "constant expression violates subrange bounds" out of the range} letter: = 'E'; caps: = letter; {the above two sentences can be compiled, however, an error occurs when you run the following comments. The code is out of the subfield} // writeln (the index of 'caps in TCAPs is: '+ inttostr (ord (CAPS); mycolors: = green; writeln ('green's index in tmycolor is:' + inttostr (ord (mycolors); readln; end.
3. F9After running, verify the result as follows:
The above code passes the test in Delphi7. Download the sample code:20151124subinterface certificate (subrange_types#.rar