Object Pascal Language Guide
Total Page:16
File Type:pdf, Size:1020Kb
Object Pascal Language Guide Borland® Object Pascal Borland Software Corporation 100 Enterprise Way, Scotts Valley, CA 95066-3249 www.borland.com Borland Software Corporation may have patents and/or pending patent applications covering subject matter in this document. The furnishing of this document does not give you any license to these patents. COPYRIGHT © 1983, 2002 Borland Software Corporation. All rights reserved. All Borland brand and product names are trademarks or registered trademarks of Borland Software Corporation. Other brand and product names are trademarks or registered trademarks of their respective holders. Printed in the U.S.A. ALP0000WW21000 1E0R0102 0203040506-9 8 7654321 D3 Contents Chapter 1 Qualified identifiers . 4-2 Introduction 1-1 Reserved words . 4-3 Directives. 4-3 What’s in this manual? . 1-1 Numerals. 4-4 Using Object Pascal . 1-1 Labels . 4-4 Typographical conventions . 1-2 Character strings . 4-4 Other sources of information . 1-2 Comments and compiler directives. 4-5 Software registration and technical support . 1-3 Expressions . 4-5 Part I Operators. 4-6 Arithmetic operators . 4-6 Basic language description Boolean operators . 4-7 Logical (bitwise) operators . 4-8 Chapter 2 String operators . 4-9 Overview 2-1 Pointer operators. 4-9 Program organization . 2-1 Set operators . 4-10 Pascal source files . 2-1 Relational operators . 4-11 Other files used to build applications . 2-2 Class operators. 4-12 Compiler-generated files . 2-3 The @ operator . 4-12 Example programs. 2-3 Operator precedence rules . 4-12 A simple console application . 2-3 Function calls . 4-13 A more complicated example . 2-4 Set constructors . 4-13 A native application . 2-5 Indexes . 4-14 Typecasts . 4-14 Chapter 3 Value typecasts. 4-14 Programs and units 3-1 Variable typecasts . 4-15 Program structure and syntax . 3-1 Declarations and statements. 4-16 The program heading . 3-2 Declarations . 4-16 The program uses clause . 3-2 Statements . 4-17 The block . 3-2 Simple statements . 4-17 Unit structure and syntax . 3-3 Assignment statements . 4-17 The unit heading . 3-3 Procedure and function calls . 4-18 The interface section . 3-4 Goto statements . 4-18 The implementation section. 3-4 Structured statements. 4-20 The initialization section. 3-4 Compound statements . 4-20 The finalization section . 3-5 With statements . 4-21 Unit references and the uses clause . 3-5 If statements . 4-22 The syntax of a uses clause . 3-6 Case statements . 4-24 Multiple and indirect unit references . 3-7 Control loops . 4-25 Circular unit references . 3-7 Repeat statements . 4-25 While statements. 4-26 Chapter 4 For statements . 4-26 Syntactic elements 4-1 Blocks and scope . 4-27 Blocks . 4-28 Fundamental syntactic elements . 4-1 Scope . 4-28 Special symbols. 4-2 Naming conflicts. 4-29 Identifiers . 4-2 iii Chapter 5 Declaring variables . 5-38 Data types, variables, and constants 5-1 Absolute addresses . 5-39 Dynamic variables . 5-39 About types. 5-1 Thread-local variables. 5-39 Simple types . 5-2 Declared constants . 5-40 Ordinal types . 5-2 True constants . 5-40 Integer types. 5-3 Constant expressions . 5-41 Character types . 5-5 Resource strings . 5-42 Boolean types . 5-5 Typed constants . 5-42 Enumerated types . 5-6 Array constants . 5-43 Subrange types . 5-8 Record constants . 5-43 Real types . 5-9 Procedural constants . 5-44 String types . .5-10 Pointer constants. 5-44 Short strings. .5-12 Long strings. .5-12 Chapter 6 WideString . .5-13 About extended character sets . .5-13 Procedures and functions 6-1 Working with null-terminated strings . .5-13 Declaring procedures and functions . 6-1 Using pointers, arrays, and Procedure declarations . 6-2 string constants . .5-14 Function declarations . 6-3 Mixing Pascal strings and null-terminated Calling conventions . 6-4 strings . .5-15 Forward and interface declarations . 6-6 Structured types . .5-16 External declarations . 6-6 Sets . .5-17 Linking to object files . 6-7 Arrays . .5-18 Importing functions from libraries. 6-7 Static arrays . .5-18 Overloading procedures and functions . 6-8 Dynamic arrays . .5-19 Local declarations . 6-10 Array types and assignments . .5-21 Nested routines . 6-11 Records . .5-21 Parameters. 6-11 Variant parts in records . .5-23 Parameter semantics . 6-12 File types . .5-25 Value and variable parameters . 6-12 Pointers and pointer types . .5-25 Constant parameters . 6-13 Overview of pointers . .5-26 Out parameters. 6-13 Pointer types . .5-27 Untyped parameters. 6-14 Character pointers . .5-27 String parameters . 6-15 Other standard pointer types . .5-28 Array parameters . 6-15 Procedural types . .5-28 Open array parameters . 6-15 Procedural types in statements and Variant open array parameters . 6-17 expressions . .5-30 Default parameters . 6-18 Variant types . .5-31 Default parameters and overloaded Variant type conversions . .5-32 routines . 6-19 Variants in expressions . .5-33 Default parameters in forward and Variant arrays . .5-34 interface declarations . 6-19 OleVariant. .5-34 Calling procedures and functions . 6-19 Type compatibility and identity . .5-35 Open array constructors . 6-20 Type identity . .5-35 Type compatibility . .5-36 Chapter 7 Assignment-compatibility. .5-36 Classes and objects 7-1 Declaring types. .5-37 Class types. 7-2 Variables . .5-37 Inheritance and scope. 7-3 iv TObject and TClass . 7-3 Chapter 8 Compatibility of class types . 7-3 Standard routines and I/O 8-1 Object types . 7-4 File input and output . 8-1 Visibility of class members . 7-4 Text files . 8-3 Private, protected, and public members . 7-5 Untyped files. 8-4 Published members. 7-5 Text file device drivers . 8-4 Automated members . 7-6 Device functions. 8-5 Forward declarations and mutually dependent The Open function. 8-5 classes . 7-6 The InOut function . 8-5 Fields . 7-7 The Flush function. 8-6 Methods. 7-8 The Close function. 8-6 Method declarations and implementations . 7-8 Handling null-terminated strings . 8-6 Inherited . 7-9 Wide-character strings . 8-7 Self . 7-9 Other standard routines . 8-7 Method binding . .7-10 Static methods. .7-10 Part II Virtual and dynamic methods. .7-10 Abstract methods . .7-12 Special topics Overloading methods . .7-12 Constructors . .7-13 Chapter 9 Destructors . .7-14 Libraries and packages 9-1 Message methods . .7-15 Calling dynamically loadable libraries . 9-1 Implementing message methods . .7-16 Static loading . 9-1 Message dispatching . .7-16 Dynamic loading. 9-2 Properties . ..