BORLAND Turbo Pasca~ Version 6.0
Total Page:16
File Type:pdf, Size:1020Kb
BORLAND Turbo Pasca~ Version 6.0 User's Guide BORLAND INTERNATIONAL INC. 1800 GREEN HILLS ROAD P.O. BOX 660001. SCOTTS VALLEY. CA 95067-0001 Copyright © 1983, 1990 by Borland International. All rights reserved. All Borland products are trademarks or registered trademarks of Borland International, Inc. Other brand and product names are trademarks or registered trademarks of their respective holders. PRINTED IN THE USA. R2 10 9 8 7 6 5 4 3 2 1 c o N T E N T s Introduction 1 Data types .......................... 31 The Turbo Pascal manuals ............. 2 Integer data types . .. 31 Installing Turbo Pascal ................ 2 Real data types .................... 32 Customizing Turbo Pascal ........... 4 Character and string data types ...... 33 Laptop systems ..................... 4 Boolean data type .................. 35 The README file . .. 4 Pointer data type .................. 36 Typefaces used in these books .......... 5 Identifiers . .. .. 37 How to contact Borland . .. 6 Operators ........................... 38 Assignment operators .............. 38 Chapter 1 Learning the new IDE 7 Arithmetic operators ............... 39 The components ...................... 8 Bitwise operators .................. 39 The menu bar and menus ............ 8 Relational operators ................ 39 Shortcuts ........................ 9 Logicaloperators .................. 40 Turbo Pascal windows . .. 11 Address operators ................. 41 Window management ............ 13 Set operators ...................... 41 The status line. .. 14 String operators ................... 41 Dialog boxes ...................... 15 Output ............................. 41 Check boxes and radio buttons .... 16 The Writeln procedure .............. 41 Input boxes and lists ............. 16 Input ............................... 43 Editing ........................... 17 Conditional statements ............... 43 Starting Turbo Pascal . .. 18 The if statement ................... 44 Creating your first program ........... 18 The case statement ................. 45 Analyzing your first program ........ 19 Loops .............................. 45 Saving your first program ........... 20 The while loop .................... 46 Compiling your first program ....... 20 The rep eat.. until loop ............... 46 Running your first program ......... 21 The for loop . .. 48 Checking the files you've created . .. 22 Procedures and functions ............. 49 Stepping up: your second program ..... 22 Program structure .................. 49 Debugging your program ........... 24 Procedure and function structure .... 50 Using the Watch window ......... 25 Sample program . .. 51 Fixing your second program. .. 25 Program comments ................ 52 Programming pizazz: your third program ............................ 26 Chapter 3 Turbo Pascal units 55 What is a unit? ...................... 55 Chapter 2 Programming in Turbo A unit's structure .................... 56 Pascal 29 Interface section ................... 57 The elements of programming ......... 29 Implementation section ............. 57 Early binding vs. late binding. .. 96 Initialization section ................ 59 Object type compatibility ........... 97 How are units used? .................. 59 Polymorphic objects . .. 99 Referencing unit declarations ........ 60 Virtual methods .................. 101 Implementation section uses clause . .. 63 Range checking virtual method Circular unit references ........... 63 calls. .. 103 Sharing other declarations ......... 65 Once virtual, always virtual ...... 103 The standard units ................... 66 An example of late binding ......... 103 System ........................... 66 Procedure or method? ............. 105 Dos .............................. 66 Object extensibility ................ 108 Overlay ........................... 66 Static or virtual methods ........... 109 Crt ............................... 66 Dynamic objects .................. 110 Printer ............................ 67 Allocation and initialization with Graph ............................ 67 New ............................ 111 Turbo3 and Graph3 ................ 67 Disposing dynamic objects ......... 112 Writing your own units . .. 68 Destructors ...................... 112 Compiling units ................... 68 An example of dynamic object An example ....................... 69 allocation ........................ 115 Units and large programs ........... 70 Disposing of a complex data structure Units as overlays. .. 71 on the heap .................... 116 The TPUMOVER utility . .. 71 Where to now? ..................... 118 Conclusion . .. 119 Chapter 4 Object-oriented programming 73 Chapter 5 Debugging Turbo Pascal Objects? ............................ 74 progrnms In Inheritance .......................... 75 Taxonomy of bugs .................. 121 Objects: records that inherit ........... 76 Compile-time errors . .. 122 Instances of object types ............ 79 Run-time errors . .. 122 An object's fields . .. 79 Logic errors ...................... 122 Good practice and bad practice ...... 79 The integrated debugger . .. 123 Methods ............................ 80 What the debugger can do ......... 123 Code and data together ............. 82 Tracing . .. 124 Defining methods . .. 82 Go to cursor .................... 124 Method scope and the Self parameter . 83 Breaking . .. 124 Object data fields and method formal Watching ...................... 124 parameters . .. 85 Evaluate/Modify ............... 124 Objects exported by units ........... 85 Navigating. .. .. 125 Private section ................... 87 In and out of the debugger ......... 125 Programming in the active voice ..... 87 Starting a debugging session ..... 126 Encapsulation ..................... 88 Restarting a debugging session ... 126 Methods: no downside ............. 89 Ending a debugging session . .. 127 Extending objects .................. 90 Tracing through your program ..... 127 Inheriting static methods ............ 93 Stepping through your program .... 129 Virtual methods and polymorphism .. 95 Using breakpoints ................ 131 ii Using Ctrl-Break . .. 133 Defining at the command line .... 165 Watching values .................. 133 Defining in the IDE. .. 165 Types of watch expressions. .. 135 Predefined symbols ............... 165 Format specifiers. .. 136 The VER60 symbol . .. 166 Typecasting .................... 137 The MSDOS and CPU86 symbols 166 Expressions .................... 138 The CPU87 symbol. .. 166 Editing and deleting watches ..... 139 The IFxxx, ELSE, and ENDIF Evaluating and modifying ......... 139 symbols ....................... 167 Modifying expressions . .. 140 The IFDEF and IFNDEF directives .. 168 Navigation. .. 142 The IFOPT directive .. .. 169 The call stack . .. 142 Optimizing code . .. 170 Finding procedures and functions . 143 Chapter 7 The IDE reference 173 Object-oriented debugging ........... 144 Stepping and tracing method calls . .. 144 Starting and exiting ................. 174 Objects in the Evaluate window .... 144 Command-line options ............ 174 Expressions in the Find Procedure The /C option .................. 174 command . .. 145 The /D option . .. 174 General issues ............ .. 145 The /E option .................. 175 Writing programs for debugging .... 145 The / G option . .. 175 Memoryissues ................... 146 The /L option .................. 175 Outside the IDE ................. 147 The /N option . .. 175 Re-configuring Turbo Pascal. .. 147 The /0 option .................. 176 Modifying your source code . .. 148 The /P option .................. 176 Turbo Debugger and the IDE ..... 149 The /S option .................. 176 Recursive routines ................ 150 The /T option .................. 176 Where debugging won't go . .. 150 The /W option ................. 176 Common pitfalls . .. 151 The /X option ....... .. 176 Error handling. .. 152 Exiting Turbo Pascal .............. 177 Input/output error checking . .. 152 :: (System) menu . .. 177 Range checking . .. 153 About ........................... 177 Other error-handling abilities . .. 154 Refresh Display ................... 177 Clear Desktop .................... 177 Chapter 6 Project management 157 File menu .......................... 178 Program organization ............... 157 Open ............................ 178 Initialization ..................... 159 Using the File list box ............ 179 The Build and Make options . .. 159 New ............................ 179 The Make option. .. 160 Save ............................ 179 The Build option .................. 161 Save As .......................... 180 The Stand-alone MAKE utility ........ 161 Save All ......................... 180 A quick example .................. 162 Change Dir ...................... 180 Creating a makefile .............. 163 Print ............................ 181 Using MAKE . .. 163 Get Info ......................... 181 Conditional compilation ............. 164 DOS Shell . .. .. .. .. .. .. ... 182 The DEFINE and UNDEF directives 164 Exit ............................. 182 iii Edit menu ......................... 182 Run-time Errors ................ 200 Restore Line ...................... 183 Syntax Options ................. 200 Cut ............................. 184 Numeric Processing . .. 201 Copy ............................ 184 Debugging . .. .. 201 Paste ............................ 184 Conditional Defines ............. 202 Copy Example . .. 184 Memory Sizes .................... 202 Show Clipboard .................. 184 Linker ..........................