PChar or PWideChar) with a string literal. For example, if
I
is a global
variable of type Integer, you can declare a
constant like
const PI: ^Integer = @I;
The compiler can resolve this because global variables are part of the code segment. So are functions and global
constants:
const PF: Pointer = @MyFunction;
Because string literals are allocated as global constants, you can initialize a PChar constant with a string literal:
const WarningStr: PChar = 'Warning!';
108
Procedures and Functions
This section describes the syntax of function and procedure declarations.
109
Procedures and Functions
This topic covers the following items:
Declaring procedures and functions
Calling conventions
Forward
and interface declarations
Declaration of external routines
Overloading procedures and functions
Local declarations and nested routines
About Procedures and Functions
Procedures and functions, referred to collectively as
routines, are self-contained statement blocks that can be called
from different locations in a program. A function is a routine that returns a value when it executes. A procedure is a
routine that does not return a value.
Function calls, because they return a value, can be used as expressions in assignments and operations. For
example,
I := SomeFunction(X);
calls
SomeFunction
and assigns the result to
I
. Function calls cannot appear on the left side of an assignment
statement.
Procedure
calls - and, when extended syntax is enabled (
{$X+}
), function calls - can be used as complete
statements. For example,
DoSomething;
calls the
DoSomething
routine; if
DoSomething
is a function, its return value is discarded.
Procedures and functions can call themselves recursively.
Declaring Procedures and Functions
When you declare
a procedure or function, you specify its name, the number and type of parameters it takes, and,
in the case of a function,
the type of its return value; this part of the declaration is sometimes called the prototype,
heading, or header. Then you write a block of code that executes whenever the procedure or function is called; this
Dostları ilə paylaş: