Description |
The $ExtendedSyntax compiler directive determines whether Delphi includes a number of Pascal language extensions or not.
This affects three areas:
1.Treating functions as procedures
The example code shows the before and after effect of $ExtendedSyntax. When On, Delphi will allow a function result to be ignored - unassigned - thereby treating the function as if it were a procedure.
2.Using Result in functions
With $ExtendedSyntax Off, you must return a function value by assigning to the pseudo variable of the same name as the function. For example :
function GetValue : Integer;
begin
GetValue := 23;
end;
With $ExtendedSyntax On, you can also assign to the pseudo variable Result as in the example code.
3.Treating Char arrays as strings
With $ExtendedSyntax On, a zero base array of Char variables can be assigned a string value. It can also be assigned from, as long as the array has a #0 value element to signify the string end.
|
| Notes | $ExtendedSyntax is equivalent to $X.
The default value is $ExtendedSyntax On
$ExtendedSyntax should be set just once in your code.
| | Related commands | $BoolEval | | Whether to short cut and and or operations | $X | | Controls some Pascal extension handling | Function | | Defines a subroutine that returns a value |
|
Download this web site as a Windows program.
|
|
|
|
Example code : Fail to compile code that does not assign a function result | begin
 // Set extended syntax off
{$ExtendedSyntax Off}
 // Call the GetValue function without assigning the result
GetValue;
end;
// A function that simply returns the value 1
function TForm1.GetValue: Integer;
begin
Result := 1;
end;
| Show full unit code | Compiltaion fails :
[Error] Unit1.pas(39): Statement expected, but expression of type 'Integer' found
[Error] Unit1.pas(45) Undeclared identifier: 'Result'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas' | Example code : Code that does not assign a function result compiles OK | begin
 // Set extended syntax on
{$ExtendedSyntax On}
 // Call the GetValue function without assigning the result
GetValue;
end;
// A function that simply returns the value 1
function TForm1.GetValue: Integer;
begin
Result := 1;
end;
| Show full unit code | Code compiles OK and runs without doing anything. |
|
|
Delphi Programming © Neil Moffatt . All rights reserved. | Home Page
|
|