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ə59/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   55   56   57   58   59   60   61   62   ...   294
DelphiLanguageGuide

Blocks and Scope
Declarations and statements are organized into blocks, which define local namespaces (or scopes) for labels and
identifiers. Blocks allow a single identifier, such as a variable name, to have different meanings in different parts of
a program. Each block is part of the declaration of a program, function, or procedure; each program, function, or
procedure declaration has one block.
Blocks
A block consists of a series of declarations followed by a compound statement. All declarations must occur together
at the beginning of the block. So the form of a block is
{declarations}
begin
  {statements}
end
The declarations section can include, in any order, declarations for variables, constants (including resource strings),
types, procedures, functions, and labels. In a program block, the declarations section can also include one or more
exports clauses (see Libraries and packages).
For example, in a function declaration like
function UpperCase(const S: string): string;
var
  Ch: Char;
  L: Integer;
  Source, Dest: PChar;
begin
45


   ...
end;
the first line of the declaration is the function heading and all of the succeeding lines make up the block. 
Ch

L
,
Source
, and 
Dest
 are local variables; their declarations apply only to the 
UpperCase
 function block and override,
in this block only, any declarations of the same identifiers that may occur in the program block or in the interface or
implementation section of a unit.
Scope
An identifier, such as a variable or function name, can be used only within the scope of its declaration. The location
of a declaration determines its scope. An identifier declared within the declaration of a program, function, or
procedure has a scope limited to the block in which it is declared. An identifier declared in the interface section of a
unit has a scope that includes any other units or programs that use the unit where the declaration occurs. Identifiers
with narrower scope, especially identifiers declared in functions and procedures, are sometimes called local, while
identifiers with wider scope are called global.
The rules that determine identifier scope are summarized below.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   55   56   57   58   59   60   61   62   ...   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