Heart. A variable of a subrange type has all the properties of variables of the host type, but its run-time value must be in the specified interval. One syntactic ambiguity arises from allowing constant expressions where Standard ▇▇▇▇▇▇ only allows simple constants. Consider the following declarations: X = 50; Y = 10; Color = (Red, Green, Blue); Scale = (X - Y) * 2..(X + Y) * 2; Standard Pascal syntax dictates that, if a type definition starts with a parenthesis, it’s an enumerated type, such as the Color type in the previous example. The intent of the declaration of scale is to define a subrange type, however. The solution is to reorganize the first subrange expression so that it doesn’t start with a parenthesis, or to set another constant equal to the value of the expression and use that constant in the type definition: type Scale = 2 * (X - Y)..(X + Y) * 2; A real type has a set of values that is a subset of real numbers, which can be represented in floating-point notation with a fixed number of digits. A value’s floating-point notation normally comprises three values—M, B, and E—such that M x BE = N, where B is always 2, and both M and E are integral values within the real type’s range. These M and E values further prescribe the real type’s range and precision. There are five kinds of real types: Real, Single, Double, Extended, and Comp. The real types differ in the range and precision of values they hold as shown in the following table: Real 2.9 x 10-39 .. 1.7 x 1038 11-12 6 Single 1.5 x 10-45 .. 3.4 x 1038 7-8 4 Double 5.0 x 10-324 .. 1.7 x 10308 15-16 8 Extended 3.4 x 10-4932 .. 1.1 x 104932 19-20 10 Comp -263+1 .. 263 -1 19-20 8 The Comp type holds only integral values within -263+1 to 263 -1, which is approximately -9.2 x 1018 to 9.2 x 1018. Object Pascal supports two models of code generation for performing real-type operations: software floating point and 80x87 floating point. The $N compiler directive is used to select the appropriate model. In the {$N+} state, which is selected by default, the generated code performs all real- type calculations using 80x87 instructions and can use all five real types. For more details on 80x87 floating-point code generation, refer to Chapter 14, “Using the 80x87.” In the {$N-} state, the generated code performs all real-type calculations in software by calling run-time library routines. For reasons of speed and code size, only operations on variables of type Real are allowed in this state. Any attempt to compile statements that operate on the Single, Double, Extended, and Comp types generates an error. {$N+} state. Unless you are compiling an application that doesn't use VCL, you should refrain from using the {$N–} state. String types A string-type value is a sequence of characters with a dynamic length attribute (depending on the actual character count during program execution), and a constant size attribute from 1 to 255. A string type declared without a size attribute is given the default size attribute 255. The length attribute’s current value is returned by the standard function Length. Operators for the string types are described in the sections “String operator” and “Relational operators” in Chapter 5. unsigned integer string type The ordering between any two string values is set by the ordering relationship of the character values in corresponding positions. In two strings of unequal length, each character in the longer string without a corresponding character in the shorter string takes on a higher or greater-than value; for example, ‘xs’ is greater than ‘x’. Null strings can be equal only to other null strings, and they hold the least string values. Characters in a string can be accessed as components of an array. See “Arrays, strings, and indexes” on page 32. The Low and High standard functions can be applied to a string-type identifier and to a variable reference of a string type. In this case, ▇▇▇ returns zero, and High returns the size attribute (maximum length) of the given string. A variable parameter declared using the OpenString identifier, or using the string keyword in the {$P+} state, is an open string parameter. Open string parameters allow string variables of varying sizes to be passed to the same procedure or function. Read about open string parameters on page 78. A structured type, characterized by its structuring method and by its component type(s), holds more than one value. If a component type is structured, the resulting structured type has more than one level of structuring. A structured type can have unlimited levels of structuring, but the maximum permitted size of any structured type in Object Pascal is 65,520 bytes. file type set type class reference type class type record type array type structured type In Standard Pascal, the word packed in a structured type’s declaration tells the compiler to compress data storage, even at the cost of diminished access to a component of a variable of this type. In Object Pascal, however, packed has no effect; instead packing occurs automatically whenever possible. Class types and class reference types are the cornerstones of object oriented programming in Object Pascal. They are described in full in Chapter 9, "Classes". Arrays have a fixed number of components of one type—the component type. In the following syntax diagram, the component type follows the word of. array type type index type ordinal type index type The index types, one for each dimension of the array, specify the number of elements. Valid index types are all ordinal types except Longint and subranges of Longint. The array can be indexed in each dimension by all values of the corresponding index type; therefore, the number of elements is the product of the number of values in each index type. The following is an example of an array type:
Appears in 1 contract
Sources: Copyright Agreement
Heart. A variable of a subrange type has all the properties of variables of the host type, but its run-time value must be in the specified interval. One syntactic ambiguity arises from allowing constant expressions where Standard ▇▇▇▇▇▇ only allows simple constants. Consider the following declarations: X = 50; Y = 10; Color = (Red, Green, Blue); Scale = (X - Y) * 2..(X + Y) * 2; Standard Pascal syntax dictates that, if a type definition starts with a parenthesis, it’s an enumerated type, such as the Color type in the previous example. The intent of the declaration of scale is to define a subrange type, however. The solution is to reorganize the first subrange expression so that it doesn’t start with a parenthesis, or to set another constant equal to the value of the expression and use that constant in the type definition: type Scale = 2 * (X - Y)..(X + Y) * 2; A real type has a set of values that is a subset of real numbers, which can be represented in floating-point notation with a fixed number of digits. A value’s floating-point notation normally comprises three values—M, B, and E—such that M x BE = N, where B is always 2, and both M and E are integral values within the real type’s range. These M and E values further prescribe the real type’s range and precision. There are five kinds of real types: Real, Single, Double, Extended, and Comp. The real types differ in the range and precision of values they hold as shown in the following table: Real 2.9 x 10-39 .. 1.7 x 1038 11-12 6 Single 1.5 x 10-45 .. 3.4 x 1038 7-8 4 Double 5.0 x 10-324 .. 1.7 x 10308 15-16 8 Extended 3.4 x 10-4932 .. 1.1 x 104932 19-20 10 Comp -263+1 .. 263 -1 19-20 8 The Comp type holds only integral values within -263+1 to 263 -1, which is approximately -9.2 x 1018 to 9.2 x 1018. Object Pascal supports two models of code generation for performing real-type operations: software floating point and 80x87 floating point. The $N compiler directive is used to select the appropriate model. In the {$N+} state, which is selected by default, the generated code performs all real- type calculations using 80x87 instructions and can use all five real types. For more details on 80x87 floating-point code generation, refer to Chapter 14, “Using the 80x87.” In the {$N-} state, the generated code performs all real-type calculations in software by calling run-time library routines. For reasons of speed and code size, only operations on variables of type Real are allowed in this state. Any attempt to compile statements that operate on the Single, Double, Extended, and Comp types generates an error. {$N+} state. Unless you are compiling an application that doesn't use VCL, you should refrain from using the {$N–} state. String types A string-type value is a sequence of characters with a dynamic length attribute (depending on the actual character count during program execution), and a constant size attribute from 1 to 255. A string type declared without a size attribute is given the default size attribute 255. The length attribute’s current value is returned by the standard function Length. Operators for the string types are described in the sections “String operator” and “Relational operators” in Chapter 5. unsigned integer string type The ordering between any two string values is set by the ordering relationship of the character values in corresponding positions. In two strings of unequal length, each character in the longer string without a corresponding character in the shorter string takes on a higher or greater-than value; for example, ‘xs’ is greater than ‘x’. Null strings can be equal only to other null strings, and they hold the least string values. Characters in a string can be accessed as components of an array. See “Arrays, strings, and indexes” on page 32. The Low and High standard functions can be applied to a string-type identifier and to a variable reference of a string type. In this case, ▇▇▇ returns zero, and High returns the size attribute (maximum length) of the given string. A variable parameter declared using the OpenString identifier, or using the string keyword in the {$P+} state, is an open string parameter. Open string parameters allow string variables of varying sizes to be passed to the same procedure or function. Read about open string parameters on page 78. A structured type, characterized by its structuring method and by its component type(s), holds more than one value. If a component type is structured, the resulting structured type has more than one level of structuring. A structured type can have unlimited levels of structuring, but the maximum permitted size of any structured type in Object Pascal is 65,520 bytes. file type set type class reference type class type record type array type structured type In Standard Pascal, the word packed in a structured type’s declaration tells the compiler to compress data storage, even at the cost of diminished access to a component of a variable of this type. In Object Pascal, however, packed has no effect; instead packing occurs automatically whenever possible. Class types and class reference types are the cornerstones of object oriented programming in Object Pascal. They are described in full in Chapter 9, "Classes". Arrays have a fixed number of components of one type—the component type. In the following syntax diagram, the component type follows the word of. array type index type index type ordinal type index type The index types, one for each dimension of the array, specify the number of elements. Valid index types are all ordinal types except Longint and subranges of Longint. The array can be indexed in each dimension by all values of the corresponding index type; therefore, the number of elements is the product of the number of values in each index type. The following is an example of an array type:
Appears in 1 contract
Sources: Copyright Agreement