Free pascal reference guide

212 706 3
Free pascal reference guide

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Free Pascal : Reference guide. Reference guide for Free Pascal, version 2.6.4 Document version 2.6 March 2014 Michaël Van Canneyt Contents 1 Pascal Tokens 11 1.1 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.2 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.3 Reserved words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.3.1 Turbo Pascal reserved words . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.3.2 Free Pascal reserved words . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.3.3 Object Pascal reserved words . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.3.4 Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.4 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.5 Hint directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.6 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.7 Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 1.8 Character strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2 Constants 20 2.1 Ordinary constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.2 Typed constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.3 Resource strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3 Types 23 3.1 Base types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.1.1 Ordinal types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Boolean types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Enumeration types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Subrange types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.1.2 Real types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.2 Character types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.2.1 Char or AnsiChar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.2.2 WideChar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.2.3 Other character types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 1 CONTENTS 3.2.4 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.2.5 Short strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.2.6 Ansistrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.2.7 UnicodeStrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.2.8 WideStrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.2.9 Constant strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.2.10 PChar - Null terminated strings . . . . . . . . . . . . . . . . . . . . . . . . 33 3.2.11 String sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.3 Structured Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Packed structured types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 3.3.1 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Static arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Dynamic arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Packing and unpacking an array . . . . . . . . . . . . . . . . . . . . . . . . 40 3.3.2 Record types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 3.3.3 Set types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 3.3.4 File types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 3.4 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 3.5 Forward type declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 3.6 Procedural types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 3.7 Variant types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 3.7.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 3.7.2 Variants in assignments and expressions . . . . . . . . . . . . . . . . . . . . 52 3.7.3 Variants and interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 3.8 Type aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 4 Variables 56 4.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 4.2 Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 4.3 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 4.4 Initialized variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 4.5 Thread Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 4.6 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 5 Objects 63 5.1 Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 5.2 Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 5.3 Static fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 5.4 Constructors and destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 5.5 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 5.5.1 Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 2 CONTENTS 5.5.2 Method invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Static methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Virtual methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Abstract methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 5.6 Visibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 6 Classes 72 6.1 Class definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 6.2 Class instantiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 6.3 Class destruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 6.4 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.4.1 Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.4.2 invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.4.3 Virtual methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.4.4 Class methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 6.4.5 Class constructors and destructors . . . . . . . . . . . . . . . . . . . . . . . 80 6.4.6 Static class methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 6.4.7 Message methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 6.4.8 Using inherited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 6.5 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 6.5.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 6.5.2 Indexed properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 6.5.3 Array properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 6.5.4 Default properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 6.5.5 Storage information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 6.5.6 Overriding properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 6.6 Class properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 6.7 Nested types, constants and variables . . . . . . . . . . . . . . . . . . . . . . . . . . 92 7 Interfaces 94 7.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 7.2 Interface identification: A GUID . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 7.3 Interface implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 7.4 Interface delegation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 7.5 Interfaces and COM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 7.6 CORBA and other Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 7.7 Reference counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 8 Generics 101 8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 8.2 Generic class definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 3 CONTENTS 8.3 Generic class specialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 8.4 A word about type compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 8.5 A word about scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 9 Extended records 110 9.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 9.2 Extended record enumerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 10 Class and record helpers 115 10.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 10.2 Restrictions on class helpers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 10.3 Restrictions on record helpers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 10.4 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 10.5 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 11 Objective-Pascal Classes 121 11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 11.2 Objective-Pascal class declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 11.3 Formal declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 11.4 Allocating and de-allocating Instances . . . . . . . . . . . . . . . . . . . . . . . . . 125 11.5 Protocol definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 11.6 Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 11.7 Name scope and Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 11.8 Selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 11.9 The id type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 11.10Enumeration in Objective-C classes . . . . . . . . . . . . . . . . . . . . . . . . . . 129 12 Expressions 131 12.1 Expression syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 12.2 Function calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 12.3 Set constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 12.4 Value typecasts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 12.5 Variable typecasts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 12.6 Unaligned typecasts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 12.7 The @ operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 12.8 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 12.8.1 Arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 12.8.2 Logical operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 12.8.3 Boolean operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 12.8.4 String operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 12.8.5 Set operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 4 CONTENTS 12.8.6 Relational operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 12.8.7 Class operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 13 Statements 146 13.1 Simple statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 13.1.1 Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 13.1.2 Procedure statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 13.1.3 Goto statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 13.2 Structured statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 13.2.1 Compound statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 13.2.2 The Case statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 13.2.3 The If then else statement . . . . . . . . . . . . . . . . . . . . . . 151 13.2.4 The For to/downto do statement . . . . . . . . . . . . . . . . . . . 153 13.2.5 The For in do statement . . . . . . . . . . . . . . . . . . . . . . . . . 154 13.2.6 The Repeat until statement . . . . . . . . . . . . . . . . . . . . . . . 161 13.2.7 The While do statement . . . . . . . . . . . . . . . . . . . . . . . . . . 161 13.2.8 The With statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 13.2.9 Exception Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 13.3 Assembler statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 14 Using functions and procedures 165 14.1 Procedure declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 14.2 Function declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 14.3 Function results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 14.4 Parameter lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 14.4.1 Value parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 14.4.2 Variable parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 14.4.3 Out parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 14.4.4 Constant parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 14.4.5 Open array parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 14.4.6 Array of const . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 14.5 Function overloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 14.6 Forward declared functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 14.7 External functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 14.8 Assembler functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 14.9 Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 14.9.1 alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 14.9.2 cdecl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 14.9.3 export . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 14.9.4 inline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 14.9.5 interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 5 CONTENTS 14.9.6 iocheck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 14.9.7 local . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 14.9.8 noreturn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 14.9.9 nostackframe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 14.9.10 overload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 14.9.11 pascal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 14.9.12 public . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 14.9.13 register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 14.9.14 safecall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 14.9.15 saveregisters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 14.9.16 softfloat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 14.9.17 stdcall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 14.9.18 varargs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 14.10Unsupported Turbo Pascal modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . 184 15 Operator overloading 185 15.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 15.2 Operator declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 15.3 Assignment operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 15.4 Arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 15.5 Comparison operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 15.6 In operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 16 Programs, units, blocks 194 16.1 Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 16.2 Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 16.3 Unit dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 16.4 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 16.5 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 16.5.1 Block scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 16.5.2 Record scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 16.5.3 Class scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 16.5.4 Unit scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 16.6 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 17 Exceptions 203 17.1 The raise statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 17.2 The try except statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 17.3 The try finally statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 17.4 Exception handling nesting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 17.5 Exception classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 6 CONTENTS 18 Using assembler 208 18.1 Assembler statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 18.2 Assembler procedures and functions . . . . . . . . . . . . . . . . . . . . . . . . . . 208 7 List of Tables 3.1 Predefined integer types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.2 Predefined integer types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.3 Boolean types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.4 Supported Real types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.5 PChar pointer arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.6 String memory sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 12.1 Precedence of operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 12.2 Binary arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 12.3 Unary arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 12.4 Logical operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 12.5 Boolean operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 12.6 Set operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 12.7 Relational operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 12.8 Class operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 13.1 Allowed C constructs in Free Pascal . . . . . . . . . . . . . . . . . . . . . . . . . . 147 14.1 Unsupported modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 8 LIST OF TABLES About this guide This document serves as the reference for the Pascal langauge as implemented by the Free Pascal compiler. It describes all Pascal constructs supported by Free Pascal, and lists all supported data types. It does not, however, give a detailed explanation of the Pascal language: it is not a tuto- rial. The aim is to list which Pascal constructs are supported, and to show where the Free Pascal implementation differs from the Turbo Pascal or Delphi implementations. The Turbo Pascal and Delphi Pascal compilers introduced various features in the Pascal language. The Free Pascal compiler emulates these compilers in the appropriate mode of the compiler: certain features are available only if the compiler is switched to the appropriate mode. When required for a certain feature, the use of the -M command-line switch or {$MODE } directive will be indicated in the text. More information about the various modes can be found in the user’s manual and the programmer’s manual. Earlier versions of this document also contained the reference documentation of the system unit and objpas unit. This has been moved to the RTL reference guide. Notations Throughout this document, we will refer to functions, types and variables with typewriter font. Files are referred to with a sans font: filename. Syntax diagrams All elements of the Pascal language are explained in syntax diagrams. Syntax diagrams are like flow charts. Reading a syntax diagram means getting from the left side to the right side, following the arrows. When the right side of a syntax diagram is reached, and it ends with a single arrow, this means the syntax diagram is continued on the next line. If the line ends on 2 arrows pointing to each other, then the diagram is ended. Syntactical elements are written like this ✲✲ syntactical elements are like this ✲✛ Keywords which must be typed exactly as in the diagram: ✲✲ keywords are like this ✲✛ When something can be repeated, there is an arrow around it: ✲✲ ✻ this can be repeated ✲✛ When there are different possibilities, they are listed in rows: ✲✲ First possibility Second possibility ✲✛ Note, that one of the possibilities can be empty: ✲✲ First possibility Second possibility ✲✛ This means that both the first or second possibility are optional. Of course, all these elements can be combined and nested. 9 [...]... type unit until uses var while with xor CHAPTER 1 PASCAL TOKENS 1.3.2 Free Pascal reserved words On top of the Turbo Pascal reserved words, Free Pascal also considers the following as reserved words: dispose exit 1.3.3 false new true Object Pascal reserved words The reserved words of Object Pascal (used in Delphi or Objfpc mode) are the same as the Turbo Pascal ones, with the following additional keywords:... Procedural • Case insensitive • Allows nested procedures • Easy input/output routines built-in The Turbo Pascal and Delphi Pascal compilers introduced various features in the Pascal language, most notably easier string handling and object orientedness The Free Pascal compiler initially emulated most of Turbo Pascal and later on Delphi It emulates these compilers in the appropriate mode of the compiler: certain... the line This kind of comment was introduced by Borland in the Delphi Pascal compiler Free Pascal supports the use of nested comments The following constructs are valid comments: (* This is an old style comment *) { This is a Turbo Pascal comment } // This is a Delphi comment All is ignored till the end of the line 12 CHAPTER 1 PASCAL TOKENS The following are valid ways of nesting comments: { Comment... chapter we describe all the Pascal reserved words, as well as the various ways to denote strings, numbers, identifiers etc 1.1 Symbols Free Pascal allows all characters, digits and some special character symbols in a Pascal source file Recognised symbols A Z a z - letter - digit - hex digit - 0 9 - 0 9 A F a f - The following characters have a special meaning: 11 CHAPTER 1 PASCAL TOKENS + - * / = . Free Pascal : Reference guide. Reference guide for Free Pascal, version 2.6.4 Document version 2.6 March 2014 Michaël Van Canneyt Contents 1 Pascal Tokens 11 1.1 Symbols. TABLES About this guide This document serves as the reference for the Pascal langauge as implemented by the Free Pascal compiler. It describes all Pascal constructs supported by Free Pascal, and lists. mode absolute and array asm begin case const constructor destructor div do downto else end file for function goto if implementation in inherited inline interface label mod nil not object of operator or packed procedure program record reintroduce repeat self set shl shr string then to type unit until uses var while with xor 13 CHAPTER 1. PASCAL TOKENS 1.3.2 Free Pascal reserved words On top of the Turbo Pascal reserved words, Free Pascal also considers the following as reserved words: dispose exit false new true 1.3.3

Ngày đăng: 23/10/2014, 11:47

Từ khóa liên quan

Mục lục

  • Pascal Tokens

    • Symbols

    • Comments

    • Reserved words

      • Turbo Pascal reserved words

      • Free Pascal reserved words

      • Object Pascal reserved words

      • Modifiers

      • Identifiers

      • Hint directives

      • Numbers

      • Labels

      • Character strings

      • Constants

        • Ordinary constants

        • Typed constants

        • Resource strings

        • Types

          • Base types

            • Ordinal types

              • Integers

              • Boolean types

              • Enumeration types

              • Subrange types

              • Real types

              • Character types

                • Char or AnsiChar

Tài liệu cùng người dùng

Tài liệu liên quan