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ə114/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   110   111   112   113   114   115   116   117   ...   294
DelphiLanguageGuide

Declaring Variables
The basic syntax for a variable declaration is
var identifierList 
:
 type;
where identifierList is a comma-delimited list of valid identifiers and type is any valid type. For example,
var I: Integer;
declares a variable 
I
 of type Integer, while
var X, Y: Real;
declares two variables - 
X
 and 
Y
 - of type Real.
Consecutive variable declarations do not have to repeat the reserved word var:
var
   X, Y, Z: Double;
   I, J, K: Integer;
   Digit: 0..9;
   Okay: Boolean;
Variables declared within a procedure or function are sometimes called local, while other variables are called global.
Global variables can be initialized at the same time they are declared, using the syntax
var identifier: type = constantExpression;
where constantExpression is any constant expression representing a value of type type. Thus the declaration
var I: Integer = 7;
is equivalent to the declaration and statement
var I: Integer;
    ...
I := 7;
Multiple variable declarations (such as 
var X, Y, Z: Real;
) cannot include initializations, nor can declarations
of variant and file-type variables.
If you don't explicitly initialize a global variable, the compiler initializes it to 0. Local variables, in contrast, cannot be
initialized in their declarations and their contents are undefined until a value is assigned to them.
When you declare a variable, you are allocating memory which is freed automatically when the variable is no longer
used. In particular, local variables exist only until the program exits from the function or procedure in which they are
declared. For more information about variables and memory management, see Memory management.
102



Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   110   111   112   113   114   115   116   117   ...   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