[Gary entsminger] turbo_pascal_for_windows_bible(book_fi.org)

440
-1

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
440
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

[Gary entsminger] turbo_pascal_for_windows_bible(book_fi.org)

  1. 1. Gary Entsminger TURBO PASCAL FOR WINDOWS B I B L EThe Most ComprehensiveTutorial and Reference for Experienced Programmers Examples, screen illustrations, and practical application samples Essential command reference section describes all features Exclusive coverage of ObjectWindows functions and the Windows API
  2. 2. The TPW Command-line Compiler T u r b o Pascal for W i n d o w s c o m m a n d - l i n e o p t i o n s u s e this syntax: TPCW [options] <file name> [options] w h e r e [options] can b e o n e or m o r e o p t i o n s , separated by spaces. Y o u designate the status o f the c o m p i l e r o p t i o n by specifying a plus ( + ) o r a m i n u s (-) after the o p t i o n . • Place a + (or a space) after an o p t i o n to turn it O n . • Place a - after the o p t i o n to turn it Off. C o m p i l e r O p t i o n s Directive options Option Meaning /$A Align data /IB Boolean evaluation /$D Debug information /IF Force FAR calls /|G Generate 286 instructions /II Input/output checking /|L Local symbol information Option Meaning /IN 80x87 code (numeric coprocessor) /|R Range checking /IS Stack-overflow checking /IV String var checking /|W Windows stack frame /IX Extended syntax Mode options Option Meaning /B Build all /F Find error /L Link buffer Option Meaning /M Make /Q Quiet (no IDE equivalent) Conditional defines option Option Meaning /D Conditional defines Option Meaning Debug options Option Meaning /G MAP file Option Meaning /V Debug info in EXE option Directory options Option Meaning /E EXE and TPU directory /I Include directories /O Object Files directories Option Meaning /R Resource directories /T Turbo directory /U Unit directories C o m m a n d - l i n e O p t i o n s a n d T h e i r IDE Equivalents. Option IDE Equivalent /|A Options/Compiler/Align data /IB Options/Compiler/Boolean evaluation /ID Options/Compiler/Debug information /IF Options/Compiler/Force far calls /|G Options/Compiler/286 code /II Options/Compiler/I/O checking /|L Options/Compiler/Local symbols /|M Options/Compiler/Memory sizes /IN Options/Compiler/80x87 code /|R Options/Compiler/Range checking /IS Options/Compiler/Stack checking /IV Options/Compiler/String var checking options /|W Optioni/Compiler/Windows stack frames /IX Options/Compiler/Extended syntax Option IDE Equivalent /B Compile/Build /D Options/Compiler/Conditional defines /E Options/Directories/EXE and TPU directory /F Search/Find error /G Options/Linker/MAP file /I Options/Compiler/Include directories /L Options/Linker/Link buffer /M Compile/Make /O Options/Directories/Object directories /Q (none) • /R Options/Directories/Resource directories /T (none) /U Options/Directories/Unit directories /V Options/Linker/Debug info in EXE
  3. 3. Turbo Pascal® for Windows™ Bible
  4. 4. Turbo Pascal® for Windows Bible Gary Entsminger SAMS A Division of Macmillan Computer Publishing 11711 North College, Carmel, Indiana 46032 USA
  5. 5. For Alison © 1992 by SAMS FIRST EDITION FIRST PRINTING—1991 All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omission. Neither is any liability assumed for damages resulting from the use of the information contained herein. For information, address SAMS, 11711 N. College Ave., Carmel, IN 46032. International Standard Book Number: 0-672-30212-8 Library of Congress Catalog No.: 91-66924
  6. 6. Publisher Richard K. Swadley Publishing Manager Joseph Wikert Managing Editor Neweleen A. Trebnik Acquisitions Editor Gregory S. Croy Development Editor Paula Northam Grady Editors Kezia Endsley Becky Freeman Jodi Jensen Rebecca Whitney Technical Editor Jeffrey Hsu Production Claudia Bell Sandy Grieshop Denny Hager Audra Hershman Bob LaRoche Laurie Lee Juli Pavey Howard Peirce Tad Ringo Bruce Steed Mary Beth Wakefield Lisa Wilson Phil Worthington Christine Young Book Design Scott Cook Michele Laseau Cover Design Tim Amrhein Indexer Johnna VanHoose Composed in Garamond and MCP Digital by Macmillan Computer Publishing. Printed in the United States of America
  7. 7. Overview Parti Working with TPW 1 Getting Started, 3 2 Elements of Application Development, 43 3 Objects for Windows, 77 4 Inheriting an Interface, 111 5 Putting Pictures in Windows, 149 6 Painting, Collecting, and Streaming, 185 Part II Advanced Topics 7 Many Windows: A Multi-Document Interface, 213 8 Resources and Control Objects, 241 9 Memory Matters, 279 10 Display Contexts and Drawing Tools, 301 11 From Program to Program Using D D E (Dynamic Data Exchange), 343 12 Sharing Libraries Using DLL (Dynamic Link Libraries), 369 13 Designing Windows Applications, 383 Part III References A ObjectWindows Objects, 405 B ObjectWindows Constants, 499 C ObjectWindows Procedures and Functions, 505 D ObjectWindows Records, 509 E The WinCrt Unit, 515 F A WinCrt Example, 525 G The Strings Unit, 539 H The Turbo Pascal for Windows System Unit, 553 I The Turbo Pascal for Windows WinDos Unit, 561 J Debugging Turbo Pascal for Windows Applications, 587 K Turbo Pascal for Windows Error Messages, 591 L W i n d o w Manager Interface Procedures and Functions, 635 M System Services Interface Procedures and Functions, 723 N G D I (Graphics Device Interface) Procedures and Functions, 793 O ObjectGraphics (A Whitewater G r o u p Graphics Toolkit), 861 P Notes for Managing a Project, 867 Q Glossary, 869 R References, Resources, and Notes, 881 S ASCII C o d e Character Set, 887 Index, 891
  8. 8. Contents I WORKING WITH TPW 1 Getting Started, 3 Creating Windows Applications, 3 System Requirements and Installation, 4 T h e Turbo Pascal for Windows IDE, 4 Turbo Pascal for Windows I D E M e n u C o m m a n d s , 7 T h e Turbo Pascal for Windows Desktop Control M e n u , 7 Restore, 8 Move, 8 Size, 8 Minimize, 8 Maximize, 8 Close, 8 Switch T o , 9 The Edit Window Control M e n u , 9 Restore, 9 Move, 9 Size, 10 Minimize, 10 Maximize, 10 Close, 10 Next, 10 The File M e n u , 10 New, 11 O p e n , 11 Save, 12 Save As, 12 Save All, 12 Print, 12 Printer Setup, 13 Exit, 14 List of Closed Files, 14 vii
  9. 9. Turbo Pascal for Windows Bible The Edit M e n u , 14 U n d o , 14 Redo, 15 Cut, 15 Copy, 15 Paste, 15 Clear, 16 The Search M e n u , 16 Find, 16 Replace, 16 Search Again, 16 G o to Line Number, 17 Search/Show Last Compile Error, 18 Search/Find Error, 18 The Run M e n u , 18 Run/Run, 18 Run/Debugger, 18 Run/Parameters, 19 The Compile M e n u , 19 Compile/Compile, 20 Compile/Make, 20 Compile/Build, 21 Compde/Primary File, 21 Compile/Clear Primary File, 21 Compile/Information, 21 Compile Information Box, 21 The Options M e n u , 22 Compiler, 22 Linker, 23 Directories, 23 Guidelines for Entering Directory Names, 24 Preferences, 25 Editor Options, 25 O p e n , 26 Save, 26 Save As, 27 Directories List Box, 28 The W i n d o w M e n u , 28 Tile, 28 Cascade, 28 Arrange Icons, 28 Close All, 29 viii
  10. 10. Contents The H e l p M e n u (Alt-H), 29 Index (Shift-Fl), 29 Topic Search (Ctrl-Fl), 29 Help/Using Help, 30 Compiler Directives, 30 ObjectWindows, 30 Procedures and Functions, 30 Reserved Words, 30 Standard Units, 31 Turbo Pascal for Windows Language, 31 Windows API, 31 About Turbo Pascal for Windows, 31 Editor, 31 The Editor C o m m a n d s , 31 The Block C o m m a n d s , 32 C o p y Block, 32 C o p y Text, 32 Cut Text, 32 Delete Block, 32 Move Block, 32 Paste from Clipboard, 33 Read Block from Disk, 33 Write Block to Disk, 33 Editor-Command Tables, 33 Auto Indent, 36 Current Compiler Options, 36 Cursor through Tabs, 36 Find Place Marker, 37 O p e n File, 37 Optimal Fill, 37 Save File, 37 Set Place, 37 S h o w Last Compile Error, 37 Tab M o d e , 37 Unindent, 37 The TPW Command-line Compiler, 38 Onward, Forward, and Upward, 41 2 Elements of Application Development, 43 Units, 44 Data Types and Identifiers, 50 Ordinal Types, 52 Boolean Types, 52 ix
  11. 11. Turbo Pascal for Windows Bible Char Type, 53 Enumerated Types, 54 Subrange Types, 54 Reals, 55 Strings, 55 Structured Types, 56 Arrays, 57 Records, 57 Object Types, 58 Sets, 59 Files, 59 Pointer Types, 60 PChar, 61 Procedural Types, 62 Turbo Pascal for Windows Reserved Words, 62 Statements, 63 assignment (:=), 64 begin..end, 64 case..of..else..end, 65 for..to/downto..do, 66 goto, 66 if..then..else, 67 inline(...), 68 procedure call, 69 repeat..until, 70 while..do, 70 with..do, 71 Debugging Turbo Pascal for Windows Applications, 72 Begin.., 75 3 Objects for Windows, 77 Overture, 77 About Turbo Pascal Windows, 78 Why Does the World Make So M u c h Sense?, 81 The Tao of Objects, 81 Inheritance, 84 Polymorphism, 86 Messages, 88 Static and Dynamic Binding, 90 Dynamic Style, 91 Extended Views, 92 X
  12. 12. Contents About Microsoft Windows, 93 Windows Structure, 95 Why O O P and Windows, 101 About Object Windows, 102 Events, Messages, and Objects, 106 Windows Messages, 107 About WinCrt, 107 Movin' O n , 109 4 Inheriting an Interface, 111 The Basiclnterface, 113 Application and W i n d o w Objects, 114 The Main Window, 116 Details, 119 W i n d o w Messages, 122 Display Contexts, 126 Using Resources, 127 Pascal and C Strings, 129 A Few Rules, 130 Adding Dialogs, 130 Adding a File Dialog, 134 T w o Kinds of File Dialogs, 135 Constants, 136 Controls, 136 Adding List Boxes, 138 Message Boxes, 141 Closing an Application, 142 Wrapping U p the Basiclnterface, 143 5 Putting Pictures in Windows, 149 Menus, IDs, and Messages, 150 Tasks, 156 Other Windows, Other Tasks, 162 Model Tasks, 162 Modeling, 163 Chaos and Strange Attractors, 166 Mathematic Attraction, 170 Order in Chaos, 171 Grand Finale, 175 xi
  13. 13. Turbo Pascal for Windows Bible 6 Painting, Collecting, and Streaming, 185 Polymorphic Collections, 187 Collecting Points, 189 Streams, 194 Putting Points in a Stream, 199 H o w Put Works, 200 Getting Points, 201 T h e S u m of Streams, 203 II ADVANCED TOPICS 7 Many Windows: A Multi-Document Interface, 213 A Basic M D I Interface, 214 Setting U p a Basic M D I Interface, 217 A Model M D I , 219 M D I Message Processing, 221 Editors, 222 A n M D I Editor, 226 M D I Wrap-up, 233 8 Resources and Control Objects, 241 Resources, 242 Resource Editors, 255 Dialog Windows, 256 Details, 260 Control Objects, 267 G r o u p Boxes, 270 Controls in Combination, 274 Bit Maps, 276 Wrap-up, 278 9 Memory Matters, 279 Memory Management, Windows Style, 280 Global and Local Memory, 283 Allocating Local Memory Blocks, 284 Global Memory Blocks, 290 A Few Advanced Memory Matters, 297 Direct Memory Access, 297 xii
  14. 14. Contents Data Segments, 297 H e a p Errors, 298 C o d e Segments, 299 w m C o m p a c t i n g , 299 Wrap-up, 300 10 Display Contexts and Drawing Tools, 301 Handling a Display Context, 302 Mapping Modes, 315 Drawing Figures, 322 A Stranger Graphics Function D e m o , 327 Wrap-up, 340 11 From Program to Program Using DDE (Dynamic Data Exchange), 343 The Clipboard, 344 Pasting from the Clipboard, 348 Sharing Data Between Applications, 353 Atoms, and So O n , 354 Wrap-up, 368 12 Sharing libraries: Using DLL (Dynamic Link Libraries), 369 DLL Details, 370 Using DLLs, 371 13 Designing Windows Applications, 383 C o m m o n User Access, 384 Objects and Windows, 386 Designing for Change, 389 Object-Oriented Application Design, 392 A T a o of Windows, 393 Object Discovery, 394 Star Wars and Dances: The Sequel, 395 Begin Discovering Objects, 400 Wrap-up, 401 xiii
  15. 15. Turbo Pascal for Windows Bible III REFERENCES A ObjectWindows Objects, 405 TApplication, 406 TBufStream, 411 TButton, 414 TCheckBox, 416 TCollection, 419 T C o m b o B o x , 427 TControl, 430 TDialog, 432 TDlgWindow, 436 TDosStream, 437 TEdit, 440 TEmsStream, 447 T G r o u p B o x , 450 TListBox, 452 TMDIClient, 457 TMDIWindow, 459 TObject, 464 TRadioButton, 465 TScrollBar, 466 TScroller, 471 TSortedCollection, 479 TStatic, 482 TStrCollection, 484 TStream, 486 TWindow, 491 B ObjectWindows Constants, 499 b f _ X X X X Constants, 499 c m X X X X Constants, 499 c o X X X X Constants, 501 e m X X X X Constants, 501 id_XXXX Constants, 502 n f X X X X Constants, 502 s t X X X X Constants, 502 t f _ X X X X Constants, 503 w b _ X X X X Constants, 503 w m _ X X X X Constants, 504 xiv
  16. 16. Contents C ObjectWindows Procedures and Functions, 505 Abstract, 506 AllocMultiSel, 506 DisposeStr, 506 FreeMultiSel, 506 GetObjectPtr, 506 LongDiv, 507 LongMul, 507 LowMemory, 507 MemAlloc, 507 NewStr, 508 RegisterType, 508 RegisterWObjects, 508 RestoreMemory, 508 D ObjectWindows Records, 509 LongRec, 509 PtrRec, 510 TDialogAttr, 510 TMessage, 510 TMultiSelRec, 511 TScrollBarTransferRec, 511 TStreamRec, 511 TWindowAttr, 512 WordRec, 513 E The WinCrt Unit, 515 AssignCrt, 516 ClrEol, 517 ClrScr, 517 CursorTo, 518 DoneWinCrt, 518 G o t o X Y , 519 InitWinCrt, 519 KeyPressed, 520 ReadBuf, 520 ReadKey, 521 ScrollTo, 521 TrackCursor, 522 WhereX, ^22 X V
  17. 17. Turbo Pascal for Windows Bible WhereY, 523 WriteBuf, 523 WriteChar, 524 F A WinCrt Example, 525 G The Strings Unit, 539 StrCat, 540 StrComp, 541 StrCopy, 542 StrDispose, 542 StrECopy, 543 StrEnd, 543 StrlComp, 544 StrLCat, 544 StrLComp, 545 StrLCopy, 546 StrLen, 546 StrLIComp, 547 StrLower, 547 StrMove, 548 StrNew, 548 StrPas, 549 StrPCopy, 550 StrPos, 550 StrRScan, 551 StrScan, 551 StrUpper, 552 H The Turbo Pascal for Windows System Unit, 553 I The Turbo Pascal for Windows WinDos Unit, 561 Constants, 561 Types, 563 A n Index of W i n D o s Procedures and Functions by Function (or Category), 566 J Debugging Turbo Pascal for Windows Applications, 587 xvi
  18. 18. Contents K Turbo Pascal for Windows Error Messages, 591 Compiler Error Messages, 592 Run-time Error Messages, 626 L Window Manager Interface Procedures and Functions, 635 Caret Procedures and Functions, 635 Clipboard Procedures and Functions, 638 Cursor Procedures and Functions, 642 Dialog-Box Procedures and Functions, 645 Display and Movement Procedures and Functions, 658 Error Procedures and Functions, 664 Hardware Procedures and Functions, 665 H o o k Procedures and Functions, 669 Information Procedures and Functions, 671 Input Procedures and Functions, 676 M e n u Procedures and Functions, 681 Message Procedures and Functions, 691 Painting Procedures and Functions, 698 Property Procedures and Functions, 705 Scrolling Procedures and Functions, 706 System Procedures and Functions, 710 Window-Creation Procedures and Functions, 711 M System Services Interface Procedures and Functions, 723 Application-Execution Functions, 723 Atom-Management Procedures and Functions, 725 Communication Procedures and Functions, 729 File I/O Procedures and Functions, 735 Initialization-File Procedures and Functions, 740 Memory-Management Procedures and Functions, 743 Module-Management Procedures and Functions, 757 Operating-System Interrupt Procedures and Functions, 761 Resource-Management Procedures and Functions, 762 Segment Procedures and Functions, 768 S o u n d Procedures and Functions, 773 String-Manipulation Procedures and Functions, 778 Task Procedures and Functions, 786 Utility Macros and Functions, 788 xvii
  19. 19. Turbo Pascal for Windows Bible N GDI (Graphics Device Interface) Procedures and Functions, 793 Bitmap Procedures and Functions, 794 Clipping Procedures and Functions, 800 Color Palette Procedures and Functions, 803 Coordinate-Translation Procedures and Functions, 807 Device-Context Procedures and Functions, 809 Device-Independent Bitmap Procedures and Functions, 812 Drawing-Attribute Procedures and Functions, 815 Drawing-Tool Procedures and Functions, 819 Environment Procedures and Functions, 826 Font Procedures and Functions, 827 Line-Drawing Procedures and Functions, 830 Mapping Procedures and Functions, 832 Metafile Procedures and Functions, 837 Printer-Control Procedures and Functions, 841 Rectangle Procedures and Functions, 842 Region Procedures and Functions, 844 Shape-Drawing Procedures and Functions, 851 Text-Drawing Procedures and Functions, 855 O ObjectGraphics (A Whitewater Group Graphics Toolkit), 861 P Notes for Managing a Project, 867 Q Glossary, 869 R References, Resources, and Notes, 881 Quotation Acknowledgments, 884 S ASCII Code Character Set, 887 Index, 891 xviii
  20. 20. Introduction Look out of any window, any morning, any evening, any day. Robert Hunter How This Book Is Organized Welcome to Turbo Pascal for Windows Bible, a b o o k that will clear many of the mysteries of Windows programming in Turbo Pascal for Windows style. Windows programming is difficult, but Turbo Pascal for Windows makes the difficulty manageable. In fact, developing Windows applications with Turbo Pascal for Windows is m u c h more fun once you get the hang of it. This bible shows you h o w to get the hang of it. Turbo Pascal for Windows Bible consists of three sections: 1. Working With T P W A n introduction to object-oriented programming and the T u r b o Pascal for W i n d o w s object library, ObjectWindows, plus the language syntax and other details. This section is loaded with practical examples and is intended to bring y o u u p to W i n d o w s application development speed in a hurry. 2. Advanced topics This section discusses s o m e of the m o r e c o m p l e x aspects of Windows application development, such as m e m o r y management,
  21. 21. Turbo Pascal for Windows Bible dynamic data exchange ( D D E ) , dynamic link libraries (DLL), design considerations, and so o n . This section is the o n e to read and study after y o u k n o w the basics of object-oriented program- ming, TPW-style. 3. Reference A detailed account of the O b j e c t W i n d o w object-oriented library, including objects, procedures, records, and constants. T h e refer- ence also is a complete description of the W i n d o w s API functions, a glossary, a reading list, and anything else that is important but does not fit in the first two sections. Reader, Who Are You? Although I cannot be sure, I assume that you already k n o w h o w to program using T u r b o Pascal (for D O S ) . T u r b o Pascal for W i n d o w s uses similar syntax and many of the same functions and procedures as Turbo Pascal (for D O S ) . Anything specific to Turbo Pascal for Windows is explained, and any differences between Turbo Pascal for Windows and Turbo Pascal (for D O S ) are discussed. If you have never programmed in Turbo Pascal for Windows, but have programmed in a procedural language such as C, C + + , or M o d u l a 2 , you probably will manage to learn Turbo Pascal for Windows programming. This b o o k makes it easier for you with a general introduction to Turbo Pascal syntax and programming. If you need more details about Turbo Pascal in general (not Windows-specific information), pick u p a g o o d Turbo Pascal (for D O S ) book, such as T o m Swan's Mastering Turbo Pascal 6 (Hayden Books) to use as a general Turbo Pascal reference. If you are already familiar with the Turbo Pascal for Windows integrated development environment (IDE) and editor, you can either glance over or skip the first chapter. Chapter 1 is primarily intended to familiarize you with the preliminar- ies: h o w to install Turbo Pascal for Windows, system requirements, h o w the IDE, compiler, and editor work, and so on. The "real" programming and object- oriented discussions start in Chapter 2. Conventions in This Book These conventions have been used throughout the b o o k to increase its readability: • All program listings; "snippets" of program code; keywords; procedure, function, and method names; types (such as base and d e r i v e d ) ; and objects ( s u c h a s B a s i c I n t e r f a c e , MainWindow, TWindow, T A p p l i c a t i o n , B a s i c A p p l i c a t i o n ) are in monospace type. X X
  22. 22. Introduction • B o o k titles, along with terms included in the Glossary (on first occurrence in the text), appear in italics. • Units, program names, and library names (ObjectWindows) appear in regular type. Acknowledgments I'd like to thank a few folks w h o have supported, advised, offered suggestions, read the manuscript, provided software, or just plain been helpful to m e during the writing of Turbo Pascal for Windows Bible: Greg Croy and Paula Northam Grady at Macmillan C o m p u t e r Publishing; N a n Borenson at Borland International; Phil Davis at the Whitewater G r o u p ; Alison Brody; Susan Allen; and Billy Ban* at the Rocky Mountain Biological Laboratory. Trademarks SAMS has made every attempt to supply trademark information about company names, products, and services mentioned in this book. Trademarks indicated below were derived from various sources. SAMS cannot attest to the accuracy of this information. Apple and Macintosh are registered trademarks of Apple Computer, Inc. Borland, Borland C + + , Turbo Debugger, and Turbo Pascal are registered trademarks of Borland International, Inc. Intel is a registered trademark of Intel Corporation. Microsoft C, Microsoft Excel, and Microsoft Word are registered trademarks of Microsoft Corporation. Windows is a trademark of Microsoft Corporation. Smalltalk is a trademark of ParcPlace systems. Whitewater Resource Toolkit is a trademark of The Whitewater G r o u p . Zortech is a trademark of Zortech, Inc. XXI
  23. 23. Turbo Pascal for Windows Bible About the Author Gary Entsminger is a writer, programmer, and consultant. H e was an associate editor for Micro Cornucopia, (the technical journal) for five years, and a columnist for Borland's Turbo Technix magazine. H e is the author of The Tao of Objects, a beginner's guide to object-oriented programming, and his articles have appeared in Dr. Dobb's Journal, Computer Language, AI Expert, Midnight Engineering, AI Week, and Neural Network News. Gary lives in the Elk Mountains of Colorado. Gary Entsminger c/o: Rocky Mountain Biological Laboratory B o x 519 Crested Butte, C O 81224 xxii
  24. 24. PARTO N E WORKINGWITH TPW
  25. 25. 1CHAPTER GETTING STARTED In earlier days, the video display was used solely to echo text that the user typed using the keyboard. In a graphical user interface, the video display itself becomes a source of user input. Charles Petzold Creating Windows Applications Y o u c a n create W i n d o w s applications using T u r b o Pascal for W i n d o w s in three different ways: 1. T h e easiest way is to use the WinCrt unit. This unit enables y o u to write "standard" T u r b o Pascal for W i n d o w s applications that use T u r b o Pascal (for D O S ) functions a n d procedures, such as Readln a n d Writeln in a scrollable w i n d o w . T h e WinCrt unit also lets y o u transfer your existing T u r b o Pascal c o d e to W i n d o w s with the least a m o u n t o f effort. I describe the WinCrt unit in m o r e detail in Chapter 2, "Ele- ments o f Application Development," a n d in the reference section. 2. Y o u also can write W i n d o w s applications in the m o r e or less "tradi- tional" way, by creating your o w n w i n d o w s a n d w i n d o w s classes, a n d setting u p your o w n message l o o p . This is the w a y "C'ers" usually d o it, a n d I briefly describe this m e t h o d in an example in Chapter 2. 3. T h e best way to write full-featured, extendable W i n d o w s applications is to use the ObjectWindows application framework (or object library).
  26. 26. 4 Parti—Working with T P W ObjectWindows uses object-oriented techniques to encapsulate c o m p l e x W i n d o w s behavior a n d make connections between W i n d o w s and your application. If y o u use ObjectWindows, W i n d o w s applica- tions are both easier to write a n d m o r e efficient. T h r o u g h o u t this book, I use a n d describe in detail h o w to use ObjectWindows. System Requirements and Installation T o r u n T u r b o Pascal for W i n d o w s , y o u n e e d Microsoft W i n d o w s , a P C with at least 2 M (megabytes) of RAM, a n d an E G A , V G A , or Hercules video adapter. Y o u also have to r u n W i n d o w s in Standard or 386 E n h a n c e d m o d e because T u r b o Pascal for W i n d o w s does not r u n in Real m o d e . In addition, if y o u plan to d e b u g in S V G A (Super V i d e o Graphics Adapter) m o d e , y o u must use dual monitors. T o install T u r b o Pascal for W i n d o w s , use the Install program o n the T u r b o Pascal for W i n d o w s distribution disks. T h e T u r b o Pascal for W i n d o w s system a n d example files o n the distribution disks are archived, so Install de-archives t h e m for y o u , puts them in convenient subdirectories, a n d automatically creates configuration files for both the command-line compiler a n d the inte- grated development environment (IDE). T o r u n the installation program from drive A, enter: C: Win A:Install or, if W i n d o w s is active, select the Program Manager's File/Run c o m m a n d and enter: A: Install Note: If y o u are a hands-on kind o f person, o r have another motive, y o u can use U n p a k . e x e to u n p a c k the archived files manually. After y o u have c o m p l e t e d the installation, a d d the T u r b o Pascal for W i n d o w s directories (for example, C: TPW; C: TPWUTILS) in the D O S path y o u specify in A U T O E X E C . B A T . If y o u d o not k n o w h o w to edit y o u r A U T O E X E C . B A T file, refer to your D O S manuals. The Turbo Pascal for Windows IDE Turbo Pascal for Windows is a complete development environment for Micro- soft W i n d o w s . It consists o f an editor, compiler, linker, a n d debugger in o n e package. Y o u c a n edit many source-code files (as a project), compile them, a n d link t h e m into an executable application without leaving the T u r b o Pascal for W i n d o w s environment. Figure 1.1 shows the T u r b o Pascal for W i n d o w s start- u p screen.
  27. 27. 1—Getting Started 5 Most of your visual activity (what y o u see) occurs in a T u r b o Pascal for W i n d o w s Edit w i n d o w . T u r b o Pascal for W i n d o w s lets y o u have as many as 32 w i n d o w s o p e n at a time, provided there is e n o u g h memory. O n l y o n e w i n d o w can be active at a time. T h e active w i n d o w is the o n e in which y o u are working (editing, compiling, and so o n ) . Figure 1.1. The Turbo Pascal for Windows start-up screen. A n Edit w i n d o w consists of • A title bar • T h e W i n d o w C o n t r o l m e n u b o x • Scroll bars • Minimize and Maximize buttons Refer to figure 1.2 for a sample Edit w i n d o w . In addition to Edit w i n d o w s , T u r b o Pascal for W i n d o w s displays various dialog w i n d o w s in response to user m e n u selections, errors, and so o n . A Replace Text dialog box, for example, appears w h e n y o u select S e a r c h / R e p l a c e T e x t from the Main m e n u , as s h o w n in figure 1.3. Dialogs (which y o u will learn m u c h m o r e about in this book) can consist of input boxes, c o m m a n d buttons, and so o n . Typically, y o u check boxes, in- put text, and specify options; then y o u click a c o m m a n d button to close the dialog box.
  28. 28. 6 Part I—Working with TPW Figure 1.2. An Edit window. Figure 1.3- A Replace Text dialog box.
  29. 29. 1—Getting Started 7 Turbo Pascal for Windows IDE Menu Commands T h e T u r b o Pascal for W i n d o w s I D E M e n u options are c o m p l e x and powerful. For your convenience, the m e n u s are separated into • D e s k t o p control • Edit w i n d o w control • File • Edit • Search • R u n • C o m p i l e • O p t i o n s • W i n d o w • H e l p m e n u s The Turbo Pascal for Windows Desktop Control Menu T h e T u r b o Pascal for W i n d o w s Control M e n u b o x is o n the far left side of the title bar. Click the control m e n u b o x o n c e or press Alt-Spacebar to display the m e n u . T h e c o m m a n d s g r o u p e d in this m e n u manage the T u r b o Pascal for W i n d o w s desktop. Each Edit w i n d o w and dialog b o x also has a (similar) Control m e n u . T h e Desktop Control m e n u c o m m a n d s are • Restore • M o v e • Size • Minimize • Maximize • Close • Switch T o
  30. 30. 8 Parti—Working with TPW Restore W h e n y o u select the Restore c o m m a n d from the Desktop Control m e n u , the T u r b o Pascal for W i n d o w s desktop w i n d o w returns to its previous size. Note: Y o u can use this c o m m a n d only if the T u r b o Pascal for W i n d o w s desktop w i n d o w is maximized or minimized. Move T h e M o v e c o m m a n d moves the desktop w i n d o w . Use the arrow keys to m o v e the w i n d o w where y o u want it and then press Enter. Y o u also can m o v e the w i n d o w by dragging its title bar. T h e title bar is the top horizontal bar of a w i n d o w ; it contains the n a m e of the file that is in the w i n d o w . Note: Y o u cannot use this c o m m a n d w h e n the desktop is maximized. Size Y o u can alter the size of the desktop w i n d o w with the Size c o m m a n d . Use the cursor arrow keys to m o v e the w i n d o w borders. T h e n press Enter w h e n y o u are satisfied with the window's size. Note: Size is an available option only w h e n the T u r b o Pascal for W i n d o w s desktop is not maximized. Minimize By selecting the Minimize c o m m a n d , y o u can turn the T u r b o Pascal for W i n d o w s desktop into the T P W icon. (An icon represents a w i n d o w in its minimized state. Applications, such as TPW, can have their o w n u n i q u e icons.) Note: Y o u can select this c o m m a n d only if the desktop w i n d o w hasn't b e e n minimized already. Maximize If y o u select the Maximize c o m m a n d , the desktop w i n d o w fills the entire screen. Note: Y o u can select this c o m m a n d only if the T u r b o Pascal for W i n d o w s desktop w i n d o w has not b e e n maximized already. Close T h e Close c o m m a n d closes the desktop and then unloads T u r b o Pascal for W i n d o w s from memory. T h e c o m m a n d is activated in two different ways, d e p e n d i n g o n the current m o d e :
  31. 31. 1—Getting Started 9 • In C U A ( c o m m a n d user access) m o d e , y o u press Alt-F4 to close the desktop. • In Alternate m o d e , y o u press Alt-X to close the desktop. Y o u also can click the close b o x in the upper-left corner to close the w i n d o w . If y o u have modified an Edit w i n d o w but have not saved the file, a dialog b o x appears so that y o u can verify whether y o u want to save the file before closing. Switch To T h e Switch T o c o m m a n d displays the Task List dialog b o x that y o u can use to switch from o n e application to another and to rearrange application w i n d o w s . The Edit Window Control Menu Each Edit w i n d o w has a Control m e n u w h e n the w i n d o w is active. T h e c o m m a n d s o n this m e n u are similar to those of the T u r b o Pascal for W i n d o w s Control m e n u . These c o m m a n d s are available o n the Edit W i n d o w Control m e n u : • Restore • M o v e • Size • Minimize • Maximize • Close • Next Restore T h e Restore c o m m a n d returns the Edit w i n d o w to its default size. If y o u have minimized or maximized the Edit w i n d o w , use Restore to return it to its previous (default) size. If y o u have not minimized or maximized the w i n d o w , the Restore c o m m a n d is disabled. Move Use the M o v e c o m m a n d to m o v e your Edit w i n d o w with keyboard keys or by dragging its title bar.
  32. 32. 10 Parti—Working with TPW After y o u select Move, use the arrow keys to m o v e the w i n d o w . W h e n you're satisfied with the window's n e w position, press Enter. Note: Y o u can use M o v e only w h e n your Edit w i n d o w isn't maximized. Size Y o u can change the size of your Edit w i n d o w using the keyboard; or, if a w i n d o w has a Resize corner, y o u can drag the corner to resize the w i n d o w . After selecting Size, use the arrow keys to m o v e the w i n d o w borders. W h e n y o u are satisfied, press Enter. Note: Y o u can use Size only w h e n your Edit w i n d o w isn't maximized or minimized. Minimize Select the Minimize c o m m a n d to shrink your Edit w i n d o w to an icon o n the T u r b o Pascal for W i n d o w s desktop. Note: Y o u can select this c o m m a n d only if the w i n d o w has not b e e n minimized already. Maximize T h e Maximize c o m m a n d enlarges the Edit w i n d o w so that it fills the T u r b o Pascal for W i n d o w s desktop. Note: Y o u can select this c o m m a n d only w h e n the w i n d o w has not b e e n maximized already. Close T h e Close c o m m a n d closes the Edit w i n d o w . Y o u also can double-click the Close b o x in the upper-left corner to close a w i n d o w . If y o u have modified text in the w i n d o w and have not saved the text, a dialog b o x appears that gives y o u the option of saving the file before y o u close. Next T h e Next c o m m a n d activates the next o p e n w i n d o w or icon. The File Menu T h e File m e n u offers y o u choices for creating n e w files, o p e n i n g and loading existing files, saving files, printing files, and exiting T u r b o Pascal for W i n d o w s . T h e File m e n u c o m m a n d s include the following:
  33. 33. 1—Getting Started 11 • N e w • O p e n • Save • Save As • Save All • Print • Printer Setup • Exit • List of closed files New N e w o p e n s a n e w Edit w i n d o w with the default n a m e N O N A M E x x . P A S (the x x stands for a n u m b e r from 00 to 99), and makes the n e w Edit w i n d o w active. A N O N A M E file is used as a temporary edit buffer. If y o u try to save a N O N A M E file, Turbo Pascal for Windows prompts y o u to n a m e it before it can be saved. Open T h e O p e n c o m m a n d displays the File O p e n dialog box. In this dialog box, y o u select the file y o u want to o p e n , as illustrated in figure 1.4. Figure 1.4. The File Open dialog box.
  34. 34. 12 Part I—Working with TPW Note: In the T u r b o Pascal for W i n d o w s D e s k t o p , y o u can work in either of two edit m o d e s . Y o u specify your choice of m o d e s using the Options/Preferences m e n u . T h e two m o d e s are C U A , the standard W i n d o w s m o d e , and Alternate, which is c o m m a n d - compatible with other Borland editors. In Alternate m o d e , press F3 to o p e n a file. Save T h e Save c o m m a n d saves to a disk the file in the active Edit w i n d o w . If the file has a default n a m e (such as N O N A M E 0 0 . P A S ) , T u r b o Pascal for W i n d o w s o p e n s the File Save As dialog b o x so that y o u can rename the file and save it in a different directory or o n a different drive. If y o u use an existing file n a m e to n a m e the file, T u r b o Pascal for W i n d o w s asks whether y o u want to overwrite the existing file. If y o u want to save all modified files, not just the file in the active Edit w i n d o w , select File/Save All. In Alternate m o d e , press F2 to save a file. Save As Save As o p e n s the File Save As dialog box, which lets y o u save the file in the active Edit w i n d o w u n d e r a different n a m e , in a different directory, or o n a different drive (see figure 1.5). All w i n d o w s that contain this file are u p d a t e d with the n e w n a m e . If y o u select a file n a m e that already exists, T u r b o Pascal for W i n d o w s first asks whether y o u want to overwrite the existing file. Save All This c o m m a n d saves all the files in o p e n Edit w i n d o w s . Print T h e Print c o m m a n d prints the contents of the active Edit w i n d o w . T u r b o Pascal for W i n d o w s expands the Tabs (that is, it replaces any Tab characters with the appropriate n u m b e r of spaces) and then prints the file. Note: T h e Print c o m m a n d is disabled if the active w i n d o w cannot be printed; for example, if n o printer is connected to your system.
  35. 35. 1—Getting Started 13 Figure 1.5. The File Save As dialog box. Printer Setup T h e Printer Setup c o m m a n d displays a Select Printer dialog b o x , which lets y o u select a printer type for T u r b o Pascal for W i n d o w s (see figure 1.6). Figure 1.6. The Select Printer dialog box.
  36. 36. 14 Parti—Working with TPW Note: If y o u d o not want to alter the way your printer is normally configured, y o u d o not have to use Printer Setup. Exit T h e Exit c o m m a n d exits T u r b o Pascal for W i n d o w s and removes it from memory. If y o u have modified a source file without saving it, T u r b o Pascal for W i n d o w s prompts y o u to save the file before exiting. T h e Exit c o m m a n d is mode-dependent: • In C U A m o d e , press Alt-F4 to exit. • In Alternate m o d e , press Alt-X to exit. list of Closed Files This c o m m a n d lists all the files that have b e e n closed since start-up. Select any closed file from the m e n u to quickly r e o p e n it. The Edit Menu T h e Edit m e n u includes c o m m a n d s to u n d o , redo, cut, copy, paste, and clear text in Edit w i n d o w s . Also, y o u can o p e n a Clipboard w i n d o w to view or edit its contents. T h e Edit m e n u c o m m a n d s are • U n d o • R e d o • C u t • C o p y • Paste • Clear Undo T h e U n d o c o m m a n d restores the most recent edit or cursor movement. U n d o inserts any characters y o u deleted, deletes any characters y o u inserted, replaces any characters y o u overwrote, and moves your cursor back to the previous position.
  37. 37. 1—Getting Started 15 If y o u u n d o a block operation, the file reappears as it did before y o u executed the block operation. If y o u press U n d o m o r e than o n c e , it continues to u n d o changes as long as it can. However, the U n d o c o m m a n d does not change an option setting that affects m o r e than o n e w i n d o w . T h e G r o u p - U n d o option in the Options/Preferences dialog b o x specifies U n d o and R e d o behavior. Redo R e d o reverses the effect of the most recent U n d o c o m m a n d . R e d o is effective only immediately after an U n d o or another Redo. A series of R e d o c o m m a n d s reverses the effects of a series of U n d o c o m m a n d s . Cut T h e C u t c o m m a n d removes the selected text from a d o c u m e n t in the Edit w i n d o w and puts the text in the Clipboard. Y o u can then use Edit/Paste to copy the text to another d o c u m e n t or to a different place in the current d o c u m e n t . T h e text remains selected in the Clipboard until y o u replace it with other text, so y o u can paste it many times, in as many files as y o u want. Copy T h e C o p y c o m m a n d does not remove the selected text; it leaves the text intact and places an exact copy of it in the Clipboard. T o paste the copied text into another d o c u m e n t , select Edit/Paste. Y o u also can copy text from a H e l p w i n d o w : • Using the keyboard, press Shift and an arrow key to select the text y o u want to copy. • Use the m o u s e to click and drag the text y o u want to copy. Paste T h e Paste c o m m a n d inserts the selected text from the Clipboard into the active w i n d o w at the current cursor position.
  38. 38. 16 Parti—Working with TPW Clear T h e Clear c o m m a n d removes t h e selected text from t h e d o c u m e n t in t h e active w i n d o w , but does not m o v e it to t h e Clipboard. T h u s , y o u cannot paste "cleared" text in a d o c u m e n t as y o u can w h e n y o u use C u t or C o p y . Note: A l t h o u g h y o u cannot paste t h e cleared text, y o u can u n d o t h e Clear c o m m a n d with U n d o . Clear is handy for deleting text without overwriting t h e current text in the Clipboard. The Search Menu T h e Search m e n u includes t h e c o m m a n d s to search for text and error locations in your files. T h e Search m e n u c o m m a n d s are • Find • Replace • Search Again • G o to Line N u m b e r • S h o w Last C o m p i l e Error • Find Error Find T h e Find c o m m a n d displays t h e Find Text dialog box, w h i c h lets y o u type in t h e text y o u want to search for. Several options in this dialog b o x let y o u specify t h e details of t h e search (see figure 1.7). Replace T h e Replace c o m m a n d displays t h e Replace Text dialog box, w h i c h lets y o u type in t h e text y o u want to search for and t h e text y o u want to replace it with (see figure 1.8). Search Again T h e Search Again c o m m a n d repeats t h e previous Find or Replace c o m m a n d . T h e previous settings y o u m a d e in t h e Find Text or Replace Text dialog b o x are in effect w h e n y o u choose Search Again. In C U A m o d e , press F3 to search again.
  39. 39. 1—Getting Started 17 Figure 1.7. The Find Text dialog box. Figure 1.8. The Replace Text dialog box. Go to line Number T h e G o to Line N u m b e r c o m m a n d displays the G o to Line N u m b e r dialog box, which prompts y o u for the line n u m b e r y o u want to find.
  40. 40. 18 Parti—Working with TPW T u r b o Pascal for W i n d o w s displays the current line n u m b e r and c o l u m n n u m b e r in the lower-left corner of every Edit w i n d o w . Search/Show Last Compile Error T h e Search/Show Last C o m p i l e Error c o m m a n d locates the previous compiler error. T h e cursor moves to the line that caused the error. If the error is not in the active w i n d o w , T u r b o Pascal for W i n d o w s makes active the w i n d o w with the previous compiler error, o p e n i n g a closed file if necessary. T h e error n u m b e r and message then appear o n the status bar. Search/Find Error T h e Search/Find Error c o m m a n d brings u p the Find Error dialog box, which lets y o u specify the address of the most recent run-time error. The Run Menu T h e R u n m e n u includes the c o m m a n d s for running your application, starting T u r b o D e b u g g e r for W i n d o w s , and specifying command-line parameters. It includes the following c o m m a n d s : • R u n • D e b u g g e r • Parameters If y o u want to use the debugger o n a file, check the Options/Linker/Debug Info in E X E check b o x before y o u compile and link your application. T h e D e b u g Info in E X E option puts the necessary information in your executable file. Run/Run T h e Run/Run c o m m a n d runs the application, using any parameters y o u pass to it through the Run/Parameters c o m m a n d . If your source c o d e has b e e n modified since the previous compilation, the compiler automatically "does a m a k e " and links your application. Run/Debugger T h e Run/Debugger c o m m a n d starts T u r b o D e b u g g e r for W i n d o w s , and allows y o u to d e b u g the application.
  41. 41. 1—Getting Started 19 Turbo Pascal for Windows tells Turbo D e b u g g e r for Windows which application to debug. C h e c k the Options/Linker/Debug Info in the E X E check b o x before y o u compile and link your application if y o u want to use Turbo D e b u g g e r to de- b u g it. T h e Options/Linker/Debug Info in E X E check b o x puts the necessary d e b u g information in the executable file. T o get the most from Turbo Debugger's symbolic debugging capabilities, y o u also should check the Options/Compiler/Debug Information b o x and the Options/Compiler/Local Symbols b o x before compiling your application. Run/Parameters T h e Run/Parameters