Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə89/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   85   86   87   88   89   90   91   92   ...   294
DelphiLanguageGuide

Structured Types
Instances of a structured type hold more than one value. Structured types include sets, arrays, records, and files as
well as class, class-reference, and interface types. Except for sets, which hold ordinal values only, structured types
can contain other structured types; a type can have unlimited levels of structuring.
By default, the values in a structured type are aligned on word or double-word boundaries for faster access. When
you declare a structured type, you can include the reserved word packed to implement compressed data storage.
For example, 
type TNumbers = packed array [1..100] of Real;
Using packed slows data access and, in the case of a character array, affects type compatibility (for more information,
see Memory management).
This topic covers the following structured types:
Sets
Arrays, including static and dynamic arrays.
Records
File types
Sets
A set is a collection of values of the same ordinal type. The values have no inherent order, nor is it meaningful for a
value to be included twice in a set.
The range of a set type is the power set of a specific ordinal type, called the base type; that is, the possible values
of the set type are all the subsets of the base type, including the empty set. The base type can have no more than
256 possible values, and their ordinalities must fall between 0 and 255. Any construction of the form
set of
 baseType
where baseType is an appropriate ordinal type, identifies a set type.
Because of the size limitations for base types, set types are usually defined with subranges. For example, the
declarations
type
 TSomeInts = 1..250; 
 TIntSet = set of TSomeInts;
create a set type called 
TIntSet
 whose values are collections of integers in the range from 1 to 250. You could
accomplish the same thing with
type TIntSet = set of 1..250;
Given this declaration, you can create a sets like this:
var Set1, Set2: TIntSet;
    ...              
    Set1 := [1, 3, 5, 7, 9];
    Set2 := [2, 4, 6, 8, 10]
You can also use the 
set of ...
 construction directly in variable declarations:
76


var MySet: set of 'a'..'z';
    ...
    MySet := ['a','b','c'];
Other examples of set types include
set of Byte
set of (Club, Diamond, Heart, Spade)
set of Char;
The in operator tests set membership:
if 'a' in MySet then ... { do something } ;
Every set type can hold the empty set, denoted by [].
Arrays
An array represents an indexed collection of elements of the same type (called the base type). Because each element
has a unique index, arrays, unlike sets, can meaningfully contain the same value more than once. Arrays can be
allocated statically or dynamically.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   85   86   87   88   89   90   91   92   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin