
Free Pascal Reference guide Reference guide for Free Pascal, version 3.2.2 Document version 3.2.2 May 2021 Michaël Van Canneyt Contents 1 Pascal Tokens 12 1.1 Symbols......................................... 12 1.2 Comments........................................ 13 1.3 Reserved words..................................... 14 1.3.1 Turbo Pascal reserved words.......................... 14 1.3.2 Object Pascal reserved words......................... 15 1.3.3 Modifiers.................................... 15 1.4 Identifiers........................................ 16 1.5 Hint directives...................................... 16 1.6 Numbers......................................... 17 1.7 Labels.......................................... 19 1.8 Character strings.................................... 19 2 Constants 21 2.1 Ordinary constants................................... 21 2.2 Typed constants..................................... 22 2.3 Resource strings..................................... 23 3 Types 25 3.1 Base types........................................ 25 3.1.1 Ordinal types.................................. 26 Integers..................................... 26 Boolean types.................................. 28 Enumeration types............................... 29 Subrange types................................. 30 Character types................................. 31 3.1.2 Real types.................................... 31 3.2 Character types..................................... 32 3.2.1 Char or AnsiChar................................ 32 3.2.2 WideChar.................................... 32 3.2.3 Other character types.............................. 32 1 CONTENTS 3.2.4 Single-byte String types............................ 32 Short strings.................................. 33 Ansistrings................................... 34 Code page conversions............................. 36 RawByteString................................. 38 UTF8String................................... 38 3.2.5 Multi-byte String types............................. 38 UnicodeStrings................................. 38 WideStrings................................... 39 3.2.6 Constant strings................................. 39 3.2.7 PChar – Null terminated strings........................ 40 3.2.8 String sizes................................... 41 3.3 Structured Types.................................... 41 Packed structured types............................. 41 3.3.1 Arrays...................................... 43 Static arrays................................... 43 Dynamic arrays................................. 44 Dynamic array Type compatibility....................... 47 Dynamic array constructor........................... 48 Dynamic array constant expressions...................... 49 Packing and unpacking an array........................ 50 3.3.2 Record types.................................. 50 Record layout and size............................. 51 Remarks and examples............................. 52 3.3.3 Set types.................................... 53 3.3.4 File types.................................... 53 3.4 Pointers......................................... 54 3.5 Forward type declarations................................ 56 3.6 Procedural types..................................... 56 3.7 Variant types...................................... 61 3.7.1 Definition.................................... 61 3.7.2 Variants in assignments and expressions.................... 62 3.7.3 Variants and interfaces............................. 63 3.8 Type aliases....................................... 63 3.9 Managed types..................................... 65 4 Variables 66 4.1 Definition........................................ 66 4.2 Declaration....................................... 66 4.3 Scope.......................................... 68 2 CONTENTS 4.4 Initialized variables................................... 68 4.5 Initializing variables using default........................... 70 4.6 Thread Variables.................................... 71 4.7 Properties........................................ 71 5 Objects 75 5.1 Declaration....................................... 75 5.2 Abstract and sealed objects............................... 76 5.3 Fields.......................................... 77 5.4 Class or Static fields................................... 78 5.5 Constructors and destructors.............................. 79 5.6 Methods......................................... 80 5.6.1 Declaration................................... 80 5.6.2 Method invocation............................... 80 Normal static methods............................. 81 Virtual methods................................. 81 Abstract methods................................ 83 Class or static methods............................. 84 5.7 Visibility........................................ 85 6 Classes 86 6.1 Class definitions..................................... 86 6.2 Abstract and sealed classes............................... 90 6.3 Normal and static fields................................. 90 6.3.1 Normal fields/variables............................. 90 6.3.2 Class fields/variables.............................. 91 6.4 Class instantiation.................................... 93 6.5 Class destruction.................................... 93 6.6 Methods......................................... 94 6.6.1 Declaration................................... 94 6.6.2 Invocation.................................... 95 6.6.3 Virtual methods................................. 95 6.6.4 Class methods................................. 96 6.6.5 Class constructors and destructors....................... 97 6.6.6 Static class methods.............................. 98 6.6.7 Message methods................................ 100 6.6.8 Using inherited................................. 101 6.7 Properties........................................ 102 6.7.1 Definition.................................... 102 6.7.2 Indexed properties............................... 104 6.7.3 Array properties................................ 105 3 CONTENTS 6.7.4 Default properties................................ 106 6.7.5 Published properties.............................. 107 6.7.6 Storage information.............................. 107 6.7.7 Overriding and redeclaring properties..................... 108 6.8 Class properties..................................... 110 6.9 Nested types, constants and variables.......................... 111 7 Interfaces 114 7.1 Definition........................................ 114 7.2 Interface identification: A GUID............................ 115 7.3 Interface implementations............................... 116 7.4 Interface inheritance.................................. 117 7.5 Interface delegation................................... 118 7.6 Interfaces and COM................................... 121 7.7 CORBA and other Interfaces.............................. 121 7.8 Reference counting................................... 122 8 Generics 123 8.1 Introduction....................................... 123 8.2 Generic type definition................................. 123 8.3 Generic type specialization............................... 126 8.4 Generic type restrictions................................ 128 8.5 Delphi compatibility.................................. 129 8.5.1 Syntax elements................................ 129 8.5.2 Record type restrictions............................ 130 8.5.3 Type overloads................................. 131 8.5.4 Name space considerations........................... 132 8.6 Type compatibility................................... 132 8.7 Using the default intrinsic................................ 134 8.8 A word about scope................................... 135 8.9 Operator overloading and generics........................... 139 9 Extended records 142 9.1 Definition........................................ 142 9.2 Extended record enumerators.............................. 144 9.3 Record operators.................................... 146 10 Class, Record and Type helpers 149 10.1 Definition........................................ 149 10.2 Restrictions on class helpers.............................. 150 10.3 Restrictions on record helpers............................. 151 4 CONTENTS 10.4 Considerations for (simple) type helpers........................ 152 10.5 A note on scope and lifetime for record and type helpers............... 153 10.6 Inheritance....................................... 155 10.7 Usage.......................................... 156 11 Objective-Pascal Classes 159 11.1 Introduction....................................... 159 11.2 Objective-Pascal class declarations........................... 159 11.3 Formal declaration................................... 161 11.4 Allocating and de-allocating Instances......................... 163 11.5 Protocol definitions................................... 164 11.6 Categories........................................ 165 11.7 Name scope and Identifiers............................... 166 11.8 Selectors......................................... 167 11.9 The id type....................................... 167 11.10Enumeration in Objective-C classes.......................... 167 12 Expressions 169 12.1 Expression syntax.................................... 170 12.2 Function calls...................................... 171 12.3 Set constructors..................................... 173 12.4 Value typecasts..................................... 174 12.5 Variable typecasts.................................... 175 12.6 Unaligned typecasts..................................
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages268 Page
-
File Size-