Download Marco Cantů Essential Pascal
Transcript
Chapter 4: User-Defined Data Types - 51 representation, which might be useful for compatibility with C or C++ libraries21. The Delphi VCL (Visual Component Library) uses enumerated types in many places. For example, the style of the border of a form is defined as follows22: type TFormBorderStyle = (bsNone, bsSingle, bsSizeable, bsDialog, bsSizeToolWin, bsToolWindow); Set Types Set types indicate a group of values, where the list of available values is indicated by the ordinal type the set is based onto. These ordinal types are usually limited, and quite often represented by an enumeration or a subrange. If we take the subrange 1..3, the possible values of the set based on it include only 1, only 2, only 3, both 1 and 2, both 1 and 3, both 2 and 3, all the three values, or none of them. A variable usually holds one of the possible values of the range of its type. A set-type variable, instead, can contain none, one, two, three, or more values of the range. It can even include all of the values. Here is an example of a set: type TLetters = set of TUppercase; Now I can define a variable of this type and assign to it some values of the original type. To indicate some values in a set, you write a comma-separated list, enclosed within square brackets. The following code shows the assignment to a variable of several values, a single value, and an empty value: var Letters1, Letters2, Letters3: TLetters; begin Letters1 := ['A', 'B', 'C']; Letters2 := ['K']; Letters3 := []; 21 You can change the default representation of enumerated types, asking for a larger one, by using the $Z compiler directive. 22 When the value of a property is an enumeration, you can choose its value from the list displayed in the Object Inspector. Marco Cantù, Essential Pascal