Scope

Scope refers to some part of your program in which a given function or variable is visible to the compiler. A global constant is in scope at all points in your program, for example, whereas a variable local to some procedure only has scope within that procedure. Consider Listing 5.2.

Listing 5.2. An Illustration of Scope
1:   program Foo;
2:
3:   {$APPTYPE CONSOLE}
4:
5:   const
6:     SomeConstant = 100;
7:
8:   var
9:     SomeGlobal: Integer;
10:    D: Double;
11:
12:  procedure SomeProc;
13:  var
14:    D, LocalD: Double;
15:  begin
16:    LocalD := 10.0;
17:    D := D - LocalD;
18:  end;
19:
20:  begin
21:    SomeGlobal := SomeConstant;
22:    D := 4.593;
23:    SomeProc;
24:  end.

SomeConstant, SomeGlobal, and D have global scope—their values are known to the compiler at all ...

Get Delphi for .NET Developer’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.