RAD Studio (Common)
|
This topic covers the following items:
When you call a procedure or function, program control passes from the point where the call is made to the body of the routine. You can make the call using the routine's declared name (with or without qualifiers) or using a procedural variable that points to the routine. In either case, if the routine is declared with parameters, your call to it must pass parameters that correspond in order and type to the routine's parameter list. The parameters you pass to a routine are called actual parameters, while the parameters in the routine's declaration are called formal parameters.
When calling a routine, remember that
You can omit parentheses when passing all and only the default parameters to a routine. For example, given the procedure
procedure DoSomething(X: Real = 1.0; I: Integer = 0; S: string = '');
the following calls are equivalent.
DoSomething(); DoSomething;
Open array constructors allow you to construct arrays directly within function and procedure calls. They can be passed only as open array parameters or variant open array parameters.
An open array constructor, like a set constructor, is a sequence of expressions separated by commas and enclosed in brackets.
For example, given the declarations
var I, J: Integer; procedure Add(A: array of Integer);
you could call the Add procedure with the statement
Add([5, 7, I, I + J]);
This is equivalent to
var Temp: array[0..3] of Integer; ... Temp[0] := 5; Temp[1] := 7; Temp[2] := I; Temp[3] := I + J; Add(Temp);
Open array constructors can be passed only as value or const parameters. The expressions in a constructor must be assignment-compatible with the base type of the array parameter. In the case of a variant open array parameter, the expressions can be of different types.
The Delphi compiler allows functions and procedures to be tagged with the inline directive to improve performance. If the function or procedure meets certain criteria, the compiler will insert code directly, rather than generating a call. Inlining is a performance optimization that can result in faster code, but at the expense of space. Inlining always causes the compiler to produce a larger binary file. The inline directive is used in function and procedure declarations and definitions, like other directives.
procedure MyProc(x:Integer); inline; begin // ... end; function MyFunc(y:Char) : String; inline; begin // .. end;
The inline directive is a suggestion to the compiler. There is no guarantee the compiler will inline a particular routine, as there are a number of circumstances where inlining cannot be done. The following list shows the conditions under which inlining does or does not occur:
The {$INLINE} compiler directive gives you finer control over inlining. The {$INLINE} directive can be used at the site of the inlined routine's definition, as well as at the call site. Below are the possible values and their meaning:
Value |
Meaning at definition |
Meaning at call site |
{$INLINE ON} (default) |
The routine is compiled as inlineable if it is tagged with the inline directive. |
The routine will be expanded inline if possible. |
{$INLINE AUTO} |
Behaves like {$INLINE ON}, with the addition that routines not marked with inline will be inlined if their code size is less than or equal to 32 bytes. |
{$INLINE AUTO} has no effect on whether a routine will be inlined when it is used at the call site of the routine. |
{$INLINE OFF} |
The routine will not be marked as inlineable, even if it is tagged with inline. |
The routine will not be expanded inline. |
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|