7.1.2 Things which are extra

Here we give a list of things which are possible in Free Pascal, but which didn't exist in Turbo Pascal or Delphi.

  1. Functions can also return complex types, such as records and arrays.
  2. You can handle function results in the function itself, as a variable. Example
    function a : longint;  
     
    begin  
       a:=12;  
       while a>4 do  
         begin  
            {...}  
         end;  
    end;

    The example above would work with TP, but the compiler would assume that the a>4 is a recursive call. To do a recursive call in this you must append () behind the function name:

    function a : longint;  
     
    begin  
       a:=12;  
       { this is the recursive call }  
       if a()>4 then  
         begin  
            {...}  
         end;  
    end;

  3. There is partial support of Delphi constructs. (see the Programmers guide for more information on this).
  4. The exit call accepts a return value for functions.
    function a : longint;  
     
    begin  
       a:=12;  
       if a>4 then  
         begin  
            exit(a*67); {function result upon exit is a*67 }  
         end;  
    end;

  5. Free Pascal supports function overloading. That is, you can dene many functions with the same name, but with dierent arguments. For example:
    procedure DoSomething (a : longint);  
    begin  
    {...}  
    end;  
     
    procedure DoSomething (a : real);  
    begin  
    {...}  
    end;

    You can then call procedure DoSomething with an argument of type Longint or Real.
    This feature has the consequence that a previously declared function must always be dened with the header completely the same:

    procedure x (v : longint); forward;  
     
    {...}  
     
    procedure x;{ This will overload the previously declared x}  
    begin  
    {...}  
    end;

    This construction will generate a compiler error, because the compiler didn't nd a denition of procedure x (v : longint);. Instead you should dene your procedure x as:

    procedure x (v : longint);  
    { This correctly defines the previously declared x}  
    begin  
    {...}  
    end;

    (The -So (see page 5.1.5) switch disables overloading. When you use it, the above will compile, as in Turbo Pascal.

  6. Operator overloading. Free Pascal allows to overload operators, i.e. you can dene e.g. the '+' operator for matrices.
  7. On FAT16 and FAT32 systems, long le names are supported.