Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework


Forward and Interface Declarations



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə128/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   124   125   126   127   128   129   130   131   ...   294
DelphiLanguageGuide

Forward and Interface Declarations
The forward directive replaces the block, including local variable declarations and statements, in a procedure or
function declaration. For example,
function Calculate(X, Y: Integer): Real; forward;
declares a function called 
Calculate
. Somewhere after the forward declaration, the routine must be redeclared in
a defining declaration that includes a block. The defining declaration for 
Calculate
 might look like this:
function Calculate;
  ... { declarations }
begin
  ... { statement block }
end;
Ordinarily, a defining declaration does not have to repeat the routine's parameter list or return type, but if it does
repeat them, they must match those in the forward declaration exactly (except that default parameters can be
omitted). If the forward declaration specifies an overloaded procedure or function, then the defining declaration must
repeat the parameter list.
A forward declaration and its defining declaration must appear in the same type declaration section. That is, you
can't add a new section (such as a var section or const section) between the forward declaration and the defining
declaration. The defining declaration can be an external or assembler declaration, but it cannot be another forward
declaration.
The purpose of a forward declaration is to extend the scope of a procedure or function identifier to an earlier point
in the source code. This allows other procedures and functions to call the forward-declared routine before it is actually
defined. Besides letting you organize your code more flexibly, forward declarations are sometimes necessary for
mutual recursions.
The forward directive has no effect in the interface section of a unit. Procedure and function headers in the interface
section behave like forward declarations and must have defining declarations in the implementation section. A routine
declared in the interface section is available from anywhere else in the unit and from any other unit or program that
uses the unit where it is declared.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   124   125   126   127   128   129   130   131   ...   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