Where can I find a comprehensive list of Delphi "compiler magic" declarations?
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 Syst开发者_如何学Cem 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.
this is offical list of magic functions. Good luck about types and constants!
It seemed a shame that no one has decided to make one so I will. I can't claim this is a comprehensive list. Its merely what I've been able to glean from either the documentation or by examining the source for missing identifiers. If you notice an omission feel free to edit the answer.
Conditional Symbols
Many conditional symbols vary depending on the compiler's version and targeted platform but the following should be defined regardless of version or platform:
- DCC
- VER
<nnn>
Constants
- CompilerVersion
- MaxInt
- MaxLongint
Routines
- Abs
- Addr
- Append
- Assert
- Assigned
- Assign
- AssignFile
- BlockRead
- BlockWrite
- Break
- Chr
- Close
- CloseFile
- Concat
- Continue
- Copy
- Dec
- Dispose
- Eof
- Eoln
- Erase
- Exclude
- Exit
- FilePos
- FileSize
- FillChar
- Finalize
- Flush
- FreeMem
- Halt
- Hi
- High
- Inc
- Include
- Initialize
- Insert
- Length
- Lo
- Low
- New
- Odd
- Pi
- Pred
- Ptr
- Read
- Readln
- ReallocMem
- Rename
- Reset
- Rewrite
- Round
- RunError
- Seek
- SeekEof
- SeekEoln
- SetLength
- SetString
- SizeOf
- Slice
- Sqr
- Str
- Succ
- Swap
- Trunc
- TypeHandle
- TypeInfo
- TypeOf
- Val
- VarCast
- VarCopy
- Write
- Writeln
Here's one that appears to apply only to linux (at least in the version I'm using):
- open
It is referenced in SysUtils.FileCreate but there is no
open
function with that signature defined anywhere in the code base.System.__open
has the same signature and points to the libcopen
function but is not referenced outside the System unit so the compiler must be doing more "magic" to resolveopen
to__open
.
Types
- AnsiChar
- Boolean
- Byte
- ByteBool
- Cardinal
- Char
- Comp
- Currency
- Double
- Extended
- Int64
- Integer
- LongBool
- Longint
- Longword
- NativeInt
- NativeUInt
- OleVariant
- Pointer
- Real
- Real48
- ShortInt
- ShortString
- Single
- SmallInt
- string (reserved word but you can "Ctrl+Click" on it if you write System.string)
- Text
- TextFile
- UInt64
- UnicodeString
- Variant
- WideChar
- WideString
- WordBool
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.
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
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.
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:
- Keywords: http://www.delphibasics.co.uk/ByType.asp?Type=Keyword
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.
I came here looking for the magic surrounding the leading underscore of functions and procedures in System.pas.
I found the utility tool DCU32INT (that parses *.dcu file and converts it into a close to Pascal form), also on github. It allows you to see both the buildin compiler defined functions that you are looking for, for example
function BlockRead
as well as the magic ones seen in the sources of system.pas, like
function _BlockRead
The functions which shows up from the .dcu file with a leading "@" sign (local symbol?) as:
function @BlockRead
精彩评论