Delphi Language Guide
Total Page:16
File Type:pdf, Size:1020Kb
Product Documentation Delphi Language Guide Version 10.3 Rio Latest version is found on online docwiki.embarcadero.com/RADStudio/en/Delphi_Language_Guide_Index © 2019 Embarcadero Technologies, Inc. Embarcadero, the Embarcadero Technologies logos, and all other Embarcadero Technologies product or service names are trademarks or registered trademarks of Embarcadero Technologies, Inc. All other trademarks are property of their respective owners. Embarcadero tools are built for elite developers who build and maintain the world’s most critical applications. Our customers choose Embarcadero because we are the champion of developers, and we help them build more secure and scalable enterprise applications faster than any other tools on the market. In fact, ninety of the Fortune 100 and an active community of more than three million users worldwide have relied on Embarcadero's award-winning products for over 30 years. If you’re trying to build a business-critical application in a demanding vertical, Embarcadero is for you. If you’re looking to write steadfast code quickly that will pass stringent code reviews faster than any other, Embarcadero is for you. We’re here to support elite developers who understand the scalability and stability of C++ and Delphi and depend on the decades of innovation those languages bring to development. We invite you to try our products for free and see for yourself. www.embarcadero.com/products/rad-studio/start-for-free Embarcadero is an Idera, Inc. company. Idera, Inc. is the parent company of global B2B software productivity brands whose solutions enable technical users to do more with less, faster. Idera, Inc. brands span three divisions – Database Tools, Developer Tools, and Test Management Tools – with products that are evangelized by millions of community members and more than 50,000 customers worldwide, including some of the world’s largest healthcare, financial services, retail, and technology companies. Embarcadero and Idera are online at www.embarcadero.com and www.ideracorp.com November, 2019 In support of the education of new developers, and as part of LearnDelphi.org, this document is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) creativecommons.org/licenses/by-sa/4.0/ Please link back to embarcadero.com and learndelphi.org Embarcadero Technologies 2 CONTENTS Language Overview....................................................................................................... 15 Program Organization ................................................................................................ 15 Delphi Source Files ................................................................................................... 16 Other Files Used to Build Applications .................................................................. 16 Compiler-Generated Files ...................................................................................... 17 Example Programs ...................................................................................................... 17 A Simple Console Application ............................................................................... 18 A More Complicated Example ............................................................................. 19 A VCL Application ................................................................................................... 20 Programs and Units Index .............................................................................................. 23 Topics ............................................................................................................................ 23 Programs and Units (Delphi) .......................................................................................... 24 Program Structure and Syntax .................................................................................. 24 The Program Heading ............................................................................................. 24 The Program Uses Clause ....................................................................................... 25 The Block ................................................................................................................... 25 Unit Structure and Syntax ........................................................................................... 26 The Unit Heading ..................................................................................................... 27 The Interface Section .............................................................................................. 27 The Implementation Section .................................................................................. 27 The Initialization Section .......................................................................................... 28 The Finalization Section ........................................................................................... 28 Unit References and the Uses Clause ...................................................................... 29 The Syntax of a Uses Clause ................................................................................... 29 Multiple and Indirect Unit References .................................................................. 30 Circular Unit References ......................................................................................... 31 Using Namespaces with Delphi .................................................................................... 32 Declaring Namespaces ............................................................................................. 33 Searching Namespaces ............................................................................................. 34 Namespace search order ...................................................................................... 34 A namespace search example ............................................................................ 34 Using Namespaces ..................................................................................................... 35 Fully qualified unit names ....................................................................................... 35 Multi-unit Namespaces ........................................................................................... 36 Fundamental Syntactic Elements Index ...................................................................... 37 Topics ............................................................................................................................ 37 Fundamental Syntactic Elements (Delphi) ................................................................. 38 The Delphi Character Set ........................................................................................... 38 Tokens ............................................................................................................................ 39 Special Symbols ....................................................................................................... 39 Identifiers ................................................................................................................... 40 Embarcadero Technologies 3 Reserved Words ....................................................................................................... 41 Directives ................................................................................................................... 42 Numerals ................................................................................................................... 44 Labels......................................................................................................................... 45 Character Strings ..................................................................................................... 45 Comments and Compiler Directives ........................................................................ 46 in ........................................................................................................................................ 47 Expressions (Delphi) ......................................................................................................... 48 Expressions .................................................................................................................... 48 Operators ...................................................................................................................... 49 Arithmetic Operators .............................................................................................. 49 Boolean Operators .................................................................................................. 50 Complete Versus Short-Circuit Boolean Evaluation ........................................... 51 Logical (Bitwise) Operators .................................................................................... 52 String Operators ....................................................................................................... 54 Pointer Operators .................................................................................................... 54 Set Operators ........................................................................................................... 55 Relational Operators ............................................................................................... 56 Class and Interface Operators .............................................................................