BORLAND Turbo Pascafbj Version 6.0
Total Page:16
File Type:pdf, Size:1020Kb
BORLAND Turbo PascafBJ Version 6.0 Turbo Vision Guide BORLAND INTERNATIONAL INC. 1800 GREEN HILLS ROAD P.O. BOX 660001, scons VALLEY, CA 95067-0001 Copyright © 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 Chapter 2 Writing Turbo Vision Why Turbo Vision? ................... 1 applications 23 What is Turbo Vision? ................. 1 Your first Turbo Vision application . .. 23 What you need to know ............... 2 The desktop, menu bar, and status line .. 25 What's in this book? ................... 2 The desktop . .. 26 The status line . .. 26 Part 1 Learning Turbo Vision Creating new commands. .. 27 Chapter 1 Inheriting the wheel 7 The menu bar ..................... 28 The framework of a windowing A note on structure . .. 30 application . .. 7 Opening a window. .. 31 A new Vision of application development. 8 Standard window equipment . .. 31 The elements of a Turbo Vision Window initialization .............. 33 application . .. 9 The Insert method ............... 33 Naming of parts .................... 9 Closing a window. .. 34 Views ........................... 9 Window behavior . .. 34 Events ........................... 9 Look through any window . .. 35 Mute objects. .. 10 What do you see? .................. 37 A common "look and feel" .......... 10 A better way to Write. .. 38 "Hello, World!" Turbo Vision style ..... 12 A simple file viewer .. .. 38 Running HELLO.PAS .............. 13 Reading a text file .. .. 39 Pulling down a menu. .. 14 Buffered drawing .................. 40 A dialog box ....................... 15 The draw buffer ................. 40 Buttons ........................... 15 Moving text into a buffer .......... 41 Getting out ........................ 16 Writing buffer contents ........... 41 Inside HELLO.PAS ................... 16 Knowing how much to write ...... 42 The application object .............. 17 Scrolling up and down ............. 42 The dialog box object .... .. 18 Multiple views in a window . .. 45 Flow of execution and debugging .... 19 Where to put the functionality ....... 46 HELLO's main program. .. 19 Making a dialog box. .. 47 The Init method ................... 20 Executing a modal dialog box ....... 49 The Run method . .. 20 Taking control ..................... 50 The Done method . .. 21 Button, button... ................. 50 Summary ........................... 21 Normal and default buttons ....... 52 Focused controls . .. 52 Take your pick .................... 53 Creating a cluster ................ 53 Frames ......................... 75 Check box values ................ 53 Buttons ......................... 75 One more cluster. .. 54 Clusters ........................ 75 Labeling the controls ............... 55 Menus .......................... 75 The input line object. .. 55 Histories . .. 76 Setting and getting data ............. 56 Input lines ...................... 76 Shortcut keys and conflicts .......... 59 List viewers ..................... 76 Ending the dialog box .............. 61 Scrolling objects ................. 76 Other dialog box controls ............. 61 Text devices ..................... 77 Static text ......................... 61 Static text ........................ 77 List viewer ........................ 61 Status lines . .. 78 List box ........................... 61 Non-visible elements .............' .... 78 History ........................... 62 Streams ........................... 78 Standard dialog boxes ................ 62 DOS streams .................... 79 Buffered streams . .. 79 Part 2 Programming Turbo Vision EMS streams .................... 79 Chapter 3 The object hierarchy 65 Resources . .. 79 Object typology . .. .. .. .. .. .. .. ... 67 Collections . .. 79 Abstract objects . .. 67 Sorted collections ................ 80 Abstract methods .................. 68 String collections ................. 80 Object instantiations and derivations ... 68 Resource collections . .. 80 Instantiation ...................... 68 String lists ........................ 80 Derivation ........................ 69 Chapter 4 Views 81 Turbo Vision methods ................ 69 "We have taken control of your TV ... " .. 81 Abstract methods .................. 69 Simple view objects .................. 82 Pseudo-abstract methods ........... 70 Setting your sights ................. 82 Virtual methods ................... 70 Getting the TPoint ............... 83 Static methods . .. 70 Getting into a TRect .............. 83 Turbo Vision fields . .. 70 Turbo Vision coordinates ......... 84 Primitive object types . .. 71 Making an appearance. .. 84 TPoint ............................ 72 Territoriality .................... 85 TRect ............................. 72 Drawing on demand ............. 85 TObject ........................... 72 Putting on your best behavior ....... 85 Views .............................. 72 Complex views ..... .. 86 Views overview ................... 73 Groups and subviews .............. 86 Groups ........................... 73 Getting into a group . .. 87 The abstract group ............... 73 Another angle on Z-order ......... 88 Desktops ....................... 74 Group portraits . .. 89 Programs ....................... 74 Relationships between views ........ 90 Applications .................... 74 The object hierarchy . .. 91 Windows ....................... 74 Ownership . .. 91 Dialog boxes .................... 74 Sub views and view trees . .. 92 Terminal views .................... 75 ii Selected and focused views . .. 95 Chapter 5 Event-driven Finding the focused view ........... 96 programming 109 How does a view get the focus? ... .. 96 Bringing Turbo Vision to life ......... 109 The focus chain ... .. 97 Reading the user's input ........... 109 Modal views ........................ 97 The nature of events . .. 111 Modifying default behavior ........... 98 Kinds of events ................... 111 The Options flag word . .. 98 Mouse events .................. 112 ofSelectable ..................... 99 Keyboard events . .. 112 ofTopSelect ..................... 99 Message events ..... .. 112 ofFirstClick ..................... 99 "Nothing" events ............... 112 ofFramed ....................... 99 Events and commands ............. 113 ofpreProcess .................... 99 Routing of events ................... 113 ofpostProcess . .. 99 Where do events come from? ....... 113 ofBuffered ..................... 100 Where do events go? .............. 114 ofTileable ...................... 100 Positional events ................ 114 ofCenter X . .. 100 Focused events ................. 115 ofCenterY . .. 100 Broadcast events . .. 115 ofCentered . .. 101 User-defined events . .. 116 The GrowMode flag byte ........... 101 Masking events ................... 116 gfGrowLoX .................... 101 Phase ........................... 116 gfGrowLoY .................... 101 The Phase field ................. 118 gfGrowHiX .................... 101 Commands ........................ 119 gfGrowHiY .................... 101 Defining commands .. .. 119 gfGrowAll ..................... 101 Binding commands ............... 120 gfGrowRel ..................... 101 Enabling and disabling commands .. 120 The DragMode flag byte ........... 102 Handling events .................... 121 dmDragMove .................. 102 The event record .................... 122 dmDragGrow .................. 102 Clearing events . .. 123 dmLimitLoX ................... 102 Abandoned events ................ 123 dmLimitLoY ................... 102 Modifying the event mechanism ...... 124 dmLimitHiX ................... 102 Centralized event gathering ........ 124 dmLimitHiY ................... 102 Overriding GetEvent. .. 125 dmLimitAll .................... 102 Using idle time ................... 125 State flag and SetState ............. 102 Inter-view communication ........... 126 Acting on a state change ......... 103 Intermediaries .................... 126 What color is your view? ............. 104 Messages among views . .. 127 Color palettes .................... 105 Who handled the broadcast? ....... 128 Inside color palettes ............... 105 Is anyone out there? ............. 128 The GetColor method ............. 106 Who's on top? .................. 129 Overriding the default colors ....... 107 Calling HandleEvent .............. 129 Adding new colors . .. 108 Help context ..................... 130 iii Chapter 6 Writing safe programs 131 The stream mechanism .............. 159 All or nothing programming ......... 131 The Put process . .. 159 . The safety pool ................... 132 The Get process . .. 160 The ValidView method .......... 133 Handling nil object pointers ........ 160 Non-memory errors ............... 134 Collections on streams: A complete Reporting errors ................ 135 example ........................... 160 Major consumers ................. 135 Adding Store methods. ,.......... 161 Registration records ............. 162 Chapter 7 Collections 137 Registering . .. 163 Collection objects ................... 138 Writing to the stream . .. 163 Collections are dynamically sized ... 138 Who gets to store things? ............ 164 Collections are polymorphic . .. 138 Subview instances ................ 164 Type checking and collections ...... 138 Peer view instances ............... 165 Collecting non-objects ........... 139 Storing and