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ə118/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   114   115   116   117   118   119   120   121   ...   294
DelphiLanguageGuide

Declared Constants
Several different language constructions are referred to as 'constants'. There are numeric constants (also called
numerals) like 17, and string constants (also called character strings or string literals) like 'Hello world!'. Every
enumerated type defines constants that represent the values of that type. There are predefined constants like True,
False, and nil. Finally, there are constants that, like variables, are created individually by declaration.
Declared constants are either true constants or typed constants. These two kinds of constant are superficially similar,
but they are governed by different rules and used for different purposes.
True Constants
A true constant is a declared identifier whose value cannot change. For example,
const MaxValue = 237;
declares a constant called 
MaxValue
 that returns the integer 237. The syntax for declaring a true constant is
const identifier = constantExpression
where identifier is any valid identifier and constantExpression is an expression that the compiler can evaluate without
executing your program.
If constantExpression returns an ordinal value, you can specify the type of the declared constant using a value
typecast. For example
const MyNumber = Int64(17);
declares a constant called 
MyNumber
, of type Int64, that returns the integer 17. Otherwise, the type of the declared
constant is the type of the constantExpression.
If constantExpression is a character string, the declared constant is compatible with any string type. If the
character string is of length 1, it is also compatible with any character type.
If constantExpression is a real, its type is Extended. If it is an integer, its type is given by the table below.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   114   115   116   117   118   119   120   121   ...   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