DELPHI enumerated in the introduction and use of data types

See when looking at delphi program aa = (a, b, c , d); such a thing, thought it was an array, colleagues say is a function of, Oh, of course, both disdain blow, so the original formula is and pay the value of an enumerated data type in a statement. Write down the following introduction and use of DELPHI enumerated data type. Laughed. .
-------------------------------------------------- ----
enumeration type
  Pascal program used not only for numerical processing, further processing more widely used non-numeric data. For example, gender, month, week, color, unit name, education, occupation and so on.
1, enumerated type definition
format: type = enum type identifier (identifier 1, identifier 2, ..., n-identifier)
2, enumerated type characteristics
① enumeration element identifier only;
e.g., the following type definition is legal:
   of the type Days = (Sun, Mon, tue, Wed, Thu, Fri, SAT);
   Colors = (Red, Yellow, Blue, White, Black, Green);
   and the following type definition is wrong:
   = colorType type ( 'Red', 'Yellow', 'Blue', 'White');
   Numbers = (1,3,5,7,9);
all of the listed elements defining the enumeration enum type which constitutes kind enumerated type range (the range).

② sequential types enumerated type is
  determined according to the order of their sequence number of each element in the enumeration defined type and serial number from zero.
For example, the definition of type days = (sun, mon, tue, wed, thu, fri, sat);
then, ord (sun) = 0, ord (mon) = 1, ......, and so on.
The first element of an enumerated type before non-trend, the last element no successor.
pred (sat) = fri; succ (sun) = mon; ord (sat) = 6;

③ same enumeration element can not appear in two or more of the enumerated type definition. The following definitions are wrong:
   type = color1 (red, Yellow, White);
     color2 for = (Blue, red, Black); 
as part of the enumeration type red color1 and color2 for
④ only enumerated type variable assignment operators and relational operators , not performs arithmetic and logical operations.
  When comparing the enumeration elements are actually comparing their number.
 For example, is defined as follows:
   type Days = (Sun, Mon, Tue, Wed, Thu, Fri, SAT);
     Colors = (Red, Yellow, Blue, White, Black, Green);
   var Color: Colors;
     WEEKDAY: Days;
 then the following statement is legal: WEEKDAY: = Mon;
   IF = WEEKDAY the then Sun the Write ( 'REST');
 the following statement is illegal:
Mon: = 1; mistake enumeration value as a variable name;
WEEKDAY: = Blue; gold for enumeration value does not belong to blue range of the weekday;
read (Color); enumerated type variables can not be assigned by the read statement;
write (weekday); writeln (blue); statement can not write output variable values enumerated type and enumeration values.

⑤ can define the type described combined with variables, such as:
  var Holiday, Workday: (Sun, Mon, Tue, Wed, Thu, Fri, SAT);
    Color: (Red, Yellow, Blue, White, Black, Green);
input and output of data may be enumerated by indirect manner. Input, and you can enter a code, by converting a program, output, print out only the character strings corresponding enumeration element. This example used in later examples.
Second, enumerated types of applications
Example 1, enter the serial number today is the day of the week, tomorrow is the output of a few English words week (Sunday numbered 0).
  type WEEKDAY = (Sun, Mon, Tue, Wed, Thu, Fri, SAT);
   var I: Integer;
     Today, Tomorrow: WEEKDAY;
  the begin
   writeln ( 'What DATE IS IT'); Readln (I);
   Case I of { The input to the converting enum}
    0: Today: Sun =;
    . 1: Today: Mon =;
    2: Today: Tue =;
    . 3: Today: Wed =;
    . 4: Today: Thu =;
    . 5: Today: Fri =;
    . 6: Today: SAT =;
   End;
IF (Today = SAT) the then Tomorrow: = Sun the else Tomorrow: = succ (Today);
   Write ( 'of The Tomorrow IS');
   Case Tomorrow of
    Sun: writeln ( 'Sunday');
    Mon: writeln ( 'Monday');
    Tue: writeln ( 'Tuesday');
    Wed: writeln ( 'wednesay');
    Thu: writeln ( 'catalog on Thursday');
    Fri: writeln ( 'Friday');
    SAT: writeln ( 'Saturday');
   End;
  End.
medals For type is a type of order, it can be used as a variable of enumeration type loop variable.

Guess you like

Origin www.cnblogs.com/blogpro/p/11345181.html