tags:

views:

328

answers:

5

A comment at the top of system.pas states:

{ Predefined constants, types, procedures, }
{ and functions (such as True, Integer, or }
{ Writeln) do not have actual declarations.}
{ Instead they are built into the compiler }
{ and are treated as if they were declared }
{ at the beginning of the System unit.     }

Obviously, that's nowhere near a comprehensive list. Does anyone know where I could find the complete list?

EDIT: The responses I've got so far seem to be a bit confused as to what I'm looking for. I'm trying to find a list of the built-in constants, types, procedures and functions that the compiler recognizes but are not declared in any unit. Examples include High(), Writeln(), Assert(), string, etc.

+3  A: 

Some of the internally defined types can be found a little further down in System.pas (around line 90 in the version shipped with Delphi 2010 Update 4). You can find them easily with a search on "built-in types"; there's a list of {$EXTERNALSYM} declarations for C++Builder where things like String, AnsiString, etc. can be found.

As far as the procedures and functions, I don't know of any list anywhere. Allen Bauer or Barry Kelly might find this and be able to help, though.

Ken White
+1  A: 

Your best option for a ready-made list is the System documentation. It lists many types and functions, and it has a separate link to a list of constants, although the list is shorter than I could have expected. The list isn't entirely magic, though. For example, there's nothing special about TInterfacedObject, but it comes from the System unit, so it's on the list.

You can't actually get a list of all compiler-magic declarations. They're magic because they can't be declared. You can't have a declaration for the High function because it works on types that haven't even been invented yet (i.e., any enumeration type). And you can't declare Writeln because it takes an arbitrary number of parameters and it supports a syntax not allowed anywhere else in the language.

What you can do is have a list of identifiers. They're identifiers that the compiler knows to treat specially if they resolve to the things designated as belonging to the System unit, but which we can still use to make our own declarations elsewhere in a program. You could declare your own Writeln function if you wanted. Your question mentions string, but that's a reserved word; you can't declare your own things called string. So although it's certainly special, I don't think it's special in quite the same way that Integer and Assert are special.

Rob Kennedy
+1 for adding a link to the documentation for the list of constants, and for explaining the various 'overloads' of compiler magic functions.
Jeroen Pluimers
A: 

For Procedures and Functions, go into the System Unit and look for the comment:

{ Procedures and functions that need compiler magic }

Below that is probably a fairly complete list. Just remove the leading underscore from each routine name.

For Keywords, the list at Delphi Basics:

are mostly "compiler magic", undeclared in any unit.

For Constants, a short list includes: MaxInt, MaxLongInt, Nil and Pi.

And as Ken said, you can find most of the Types near the top of the System unit.

lkessler
Not what Mason wanted. This gives a complete list for the whole RTL, not just the "Magic" ones.
François
Updated my answer.
lkessler
+7  A: 

this is offical list of magic functions. Good luck about types and constants!

AhmetC
That's got most of the procedures and functions, but none of the constants and types.
lkessler
Right, i updated my answer.
AhmetC
Awesome! I did not know this...
Mick
+1  A: 

The list of types and consts is also not official, but can be deduced from the System.pas sources if you have them. It also depends on the kind of compiler (support for Unicode, Kylix, .NET, etc.).

This is the relevant portion from the Delphi 2010 System.pas:

{$EXTERNALSYM CompilerVersion}

{$EXTERNALSYM Boolean     'bool'             } {$OBJTYPENAME Boolean    'Bo'}
{$NODEFINE    ShortInt    'ShortInt'         } {$OBJTYPENAME ShortInt   'Bzc'} { signed char }
{-EXTERNALSYM ShortInt    'signed char'      } {-OBJTYPENAME ShortInt   'Bzc'}
{$EXTERNALSYM SmallInt    'short'            } {$OBJTYPENAME SmallInt   'Bs'}
{$EXTERNALSYM Integer     'int'              } {$OBJTYPENAME Integer    'Bi'}
{$NODEFINE    Byte        'Byte'             } {$OBJTYPENAME Byte       'Buc'} { unsigned char }
{$NODEFINE    Word        'Word'             } {$OBJTYPENAME Word       'Bus'} { unsigned short }
{$EXTERNALSYM Cardinal    'unsigned'         } {$OBJTYPENAME Cardinal   'Bui'}
{$EXTERNALSYM Int64       '__int64'          } {$OBJTYPENAME Int64      'Bj'}
{$EXTERNALSYM UInt64      'unsigned __int64' } {$OBJTYPENAME UInt64     'Buj'}
{$EXTERNALSYM NativeInt   'int'              } {$OBJTYPENAME NativeInt  'Bi'}
{$EXTERNALSYM NativeUInt  'unsigned'         } {$OBJTYPENAME NativeUInt 'Bui'}
{$EXTERNALSYM Single      'float'            } {$OBJTYPENAME Single     'Bf'}
{$EXTERNALSYM Double      'double'           } {$OBJTYPENAME Double     'Bd'}
{$NODEFINE    Extended    'Extended'         } {$OBJTYPENAME Extended   'Bg'} { long double }
{$NODEFINE    Currency    'Currency'    'CurrencyBase'    } {$OBJTYPENAME Currency    'NCurrency'}
{$NODEFINE    Comp        'Comp'        'CompBase'        } {$OBJTYPENAME Comp        'NComp'}
{$EXTERNALSYM Real        'double'                        } {$OBJTYPENAME Real        'Bd'}
{$NODEFINE    ShortString 'ShortString' 'ShortStringBase' } {$OBJTYPENAME ShortString 'N%SmallString$iuc$255%'}
{$NODEFINE    OpenString  'OpenString'       } {$OBJTYPENAME OpenString 'Bxpc'} { char * const }
{$NODEFINE    File        'file'             } {$OBJTYPENAME File       'Nfile'}
{$NODEFINE    Text        'TextFile'         } {$OBJTYPENAME Text       'NTextfile'}
{$NODEFINE    ByteBool    'ByteBool'         } {$OBJTYPENAME ByteBool   'Buc'} { unsigned char }
{$NODEFINE    WordBool    'WordBool'         } {$OBJTYPENAME WordBool   'Bus'} { unsigned short }
{$EXTERNALSYM LongBool    'BOOL'             } {$OBJTYPENAME LongBool   'Bi'}  { int } { from windef.h }
{$NODEFINE    Real48      } { not supported in C++ }
{$EXTERNALSYM Pointer     'void *'    }
{$NODEFINE    PWideChar   'WideChar *'}
{$EXTERNALSYM PAnsiChar   'char *'    }
{$NODEFINE    Variant     } { defined in sysvari.h }
{$NODEFINE    OleVariant  } { defined in sysvari.h }
{$NODEFINE    LongInt     } { alias of Integer     }
{$NODEFINE    LongWord    } { alias of Cardinal    }
{$NODEFINE    TextFile    } { alias of Text        }
{$IFDEF UNICODE}
  {$EXTERNALSYM AnsiChar     'char'          } {$OBJTYPENAME AnsiChar 'Bc'}
  {$IFDEF LINUX}
    {$NODEFINE  Char         'WideChar'      } {$OBJTYPENAME Char     'Bus'} { unsigned short }
                                               {-OBJTYPENAME Char     'BCs'} { char16_t }
  {$ELSE}
    {$NODEFINE  Char         'WideChar'      } {$OBJTYPENAME Char     'Bb'}  { wchar_t }
                                               {-OBJTYPENAME Char     'BCs'} { char16_t }
  {$ENDIF}
  {$NODEFINE    string       'UnicodeString' } {$OBJTYPENAME string   'NUnicodeString'} { defined in vcl/ustring.h }
  {-NODEFINE    string       'String'        } {$OBJTYPENAME string   'NUnicodeString'} { defined in vcl/ustring.h }
  {$NODEFINE    AnsiString   } { defined in vcl/dstring.h }
  {$NODEFINE    WideString   } { defined in vcl/wstring.h }
  {$NODEFINE    PChar        } { alias of PWideChar  }
  {$NODEFINE    WideChar     } { alias of Char       }
  {$NODEFINE    UnicodeString} { alias of string     }
{$ELSE}
  {$EXTERNALSYM Char         'char'          } {$OBJTYPENAME Char     'Bc'}
  {$IFDEF LINUX}
    {$NODEFINE  WideChar     'WideChar'      } {$OBJTYPENAME WideChar 'Bus'} { unsigned short }
                                               {-OBJTYPENAME WideChar 'BCs'} { char16_t }
  {$ELSE}
    {$NODEFINE  WideChar     'WideChar'      } {$OBJTYPENAME WideChar 'Bb'}  { wchar_t }
                                               {-OBJTYPENAME WideChar 'BCs'} { char16_t }
  {$ENDIF}
  {$NODEFINE    string       'AnsiString'    } { defined in vcl/dstring.h }
  {-NODEFINE    string       'String'        } { defined in vcl/dstring.h }
  {$NODEFINE    WideString   } { defined in vcl/wstring.h }
  {$NODEFINE    UnicodeString} { defined in vcl/ustring.h }
  {$NODEFINE    PChar        } { alias of PAnsiChar  }
  {$NODEFINE    AnsiChar     } { alias of Char       }
  {$NODEFINE    AnsiString   } { alias of string     }
{$ENDIF}

--jeroen

Jeroen Pluimers