Extended syntax (Delphi)
Go Up to Delphi Compiler Directives (List) Index
| Type | Switch | 
| Syntax | {$X+} or {$X-} {$EXTENDEDSYNTAX ON} or {$EXTENDEDSYNTAX OFF} | 
| Default | {$X+} {$EXTENDEDSYNTAX ON} | 
| Scope | Global | 
Remarks
Note:  The $X directive is provided for backward compatibility. You should not use the {$X-} mode when writing Delphi applications.
The $X directive enables or disables Delphi's extended syntax:
- Function statements. In the {$X+} mode, function calls can be used as procedure calls; that is, the result of a function call can be discarded, rather than passed to another function or used in an operation or assignment. Generally, the computations performed by a function are represented through its result, so discarding the result makes little sense. Sometimes, however, a function is called because it performs a task such as setting the value of a global variable, without producing a useful result.
- The Result variable. In the {$X+} mode, the predefined variable Result can be used within a function body to hold the function's return value.
- Null-terminated strings. In the {$X+} mode, Delphi strings can be assigned to zero-based character arrays (array[0..X] of Char), which are compatible with PChar types.
When {$X+} is in effect (the default), you can omit the caret when referencing pointers. When declaring a pointer, however, the caret is required.
For example:
{$X+}
type
   PMyRec = ^TMyRec;
   TMyRec = record
     Data: Integer;
   end;
 var
   MyRec: PMyRec;
 begin
   New(MyRec);
   MyRec.Data := 42;  {#1}
 end.
Normally, the line marked #1 would be expressed as:
MyRec^.Data := 42;
But with extended syntax enabled, the caret can be omitted.