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. 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
7. 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
8. 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
9. 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
10. 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
11. 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
12. 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
13. 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
14. 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
15. 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
16. 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
17. 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
18. 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
19. 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
20. 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
21. 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,
22. 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
23. 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
24. 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
27. 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).
28. 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.
29. 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.
30. 6 Part I—Working with TPW
Figure 1.2. An Edit window.
Figure 1.3- A Replace Text dialog box.
31. 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
32. 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 :
33. 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.
34. 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:
35. 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.
36. 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.
37. 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.
38. 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.
39. 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.
40. 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.
41. 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.
42. 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.
43. 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 c o m m a n d passes parameters to your application program
w h e n y o u run it as though y o u were running the application from the Program
Manager's File/Run m e n u .
When y o u select this c o m m a n d , the Parameters dialog b o x appears. Y o u r
job is to specify the command-line arguments (see figure 1.9).
Figure 1.9. The Parameters dialog box.
The Compile Menu
Y o u use the c o m m a n d s o n the C o m p i l e m e n u to compile, make, or build your
application program.
44. 20 Parti—Working with TPW
T o u s e the Compile c o m m a n d , y o u must have a file o p e n in an active
window. T o use Make a n d Build, y o u must have a primary file defined. Select
from these c o m m a n d s :
• C o m p i l e
• Make
• Build
• Primary File
• Clear Primary File
• Information
Compile/Compile
T h e Compile/Compile c o m m a n d compiles the file in the active Edit window.
A C o m p i l e Status information b o x displays the compilation progress a n d
results.
If a n error occurred, the status bar displays the error line a n d highlights
the error.
Click your m o u s e or press a key to clear the message so that y o u c a n
correct the error.
Compile/Make
T h e Compile/Make c o m m a n d creates a . E X E file according to these rules:
• If a primary file has b e e n n a m e d in the Primary File dialog b o x , that file
is compiled. Otherwise, the file in the active Edit w i n d o w is compiled.
Turbo Pascal for Windows checks all files affecting the compiled file's
performance to verify that they exist a n d that they are current.
• If the source file for a unit has b e e n modified since the . T P U (object
code) file was created, the modified unit is recompiled.
• If the interface for a unit has changed, any unit that d e p e n d s o n it is
recompiled.
• If a unit links in a . O B J file (external routines), a n d the . O B J file is
newer than the unit's . T P U file, the unit is recompiled.
• If a unit contains an Include file a n d the Include file is newer than that
unit's . T P U file, the unit is recompiled.
• If the source to a unit (.TPU file) cannot b e located, the unit is not
compiled.
This option is identical to Compile/Build, except it is conditional. Build
rebuilds all files, whether or not they are current.
45. 1—Getting Started 21
Compile/Build
T h e Compile/Build c o m m a n d rebuilds all the c o m p o n e n t s of your application,
whether or not they are current.
This option is identical to Compile/Make, except it is unconditional. M a k e
rebuilds only those files that are not current.
T h e Compile/Build c o m m a n d recompiles all the files included in the
primary file.
If y o u abort a Compile/Build c o m m a n d by pressing Ctrl-Break or receive
errors that terminate the build, y o u can restart the build where it was termi-
nated by selecting Compile/Make.
Compfle/Primary File
T h e Compile/Primary File c o m m a n d displays the Primary File dialog box, which
lets y o u specify which .PAS file will be compiled w h e n y o u choose Compile/
Make or Compile/Build.
Use Compile/Primary File w h e n y o u are working o n an application that
uses several unit (.TPU) or Include files. Regardless of the file y o u are editing,
Compile/Make and Compile/Build always operate o n your primary file. If y o u
specify another file as a primary file, but want to compile only the file in the
active Edit window, choose C o m p i l e .
Compile/Clear Primary File
T h e Compile/Clear Primary File c o m m a n d removes the n a m e of the primary file
y o u specified with the Compile/Primary File c o m m a n d . If a primary file has not
b e e n specified, however, the c o m m a n d is disabled.
Compile/Information
T h e Compile/Information c o m m a n d displays the C o m p i l e Information box,
the n a m e of your primary file (if y o u are using o n e ) , a n d the n a m e of the
previous file compiled.
Compile Information Box
T h e C o m p i l e Information b o x lists:
• T h e n a m e of the primary file (if y o u are using one)
• T h e n a m e of the previous file c o m p i l e d
• T h e source compiled
• C o d e size
• Data size
46. 22 Parti—Working with TPW
• Stack size
• Local heap size
The Options Menu
T h e Options m e n u contains c o m m a n d s for viewing and changing various
default settings in Turbo Pascal for Windows. Most of the c o m m a n d s in this
m e n u initiate a dialog b o x . T h e c o m m a n d s are
• Compiler
• Linker
• Directories
• Preferences
• O p e n
• Save
• Save As
Compiler
T h e Options/Compiler c o m m a n d displays the Compiler O p t i o n s dialog b o x ,
which lets y o u select the options that determine howyour c o d e is compiled (see
figure 1.10).
Figure 1.10. The Compiler Options dialog box.
47. 1—Getting Started 23
Linker
T h e Options/Linker c o m m a n d displays the Linker O p t i o n s dialog box, which
lets y o u select the options that determine h o w your application files are linked,
as s h o w n in figure 1.11.
Figure 1.11. The Linker Options dialog box.
Map File options
T h e M a p File options (Off, Segments, Publics, and Detailed) determine the type
of m a p file produced.
Link Buffer File options
T h e Link Buffer File options (Memory or Disk) specify the location of the link
buffer.
Debug Info in E X E option
T h e D e b u g Info in E X E option puts d e b u g information in your program's
executable file.
Directories
T h e Directories c o m m a n d o p e n s the Directories dialog box, where y o u specify
the directories y o u want Turbo Pascal for Windows to use w h e n running and
storing your application programs, as illustrated in figure 1.12.
48. 24 Part I—Working with TPW
Figure 1.12. The Directories dialog box.
With the options in this dialog box, y o u decide where T u r b o Pascal for
W i n d o w s finds the files it needs to compile, link, and output executable files.
T h e E X E and T P U Directory input b o x specifies the directory that stores
your .EXE and .TPU (object code) files.
T h e Include Directories input b o x specifies the directories that contain
your standard Include files.
T h e Unit Directories input b o x specifies the directories that contain your
T u r b o Pascal for W i n d o w s unit files.
The Object Directories input b o x specifies the directories that contain
your . O B J files (assembly language routines).
The Resource Directories input b o x specifies the directories in which your
resource files are kept.
Guidelines for Entering Directory Names
Use the following guidelines w h e n y o u enter directories in the Options/
Directories input boxes:
• Separate multiple directory path names (if allowed) with a semicolon (;).
• Use a m a x i m u m of 127 characters (including white space). White space
before and after the semicolon is allowed but not required.
• Relative and absolute path names are allowed, including path names
relative to the logged position in drives other than the current o n e .
49. 1—Getting Started 25
For example:
C: ; D:TPW
D:;C:TPW;D:TPW
Preferences
T h e Options/Preferences m e n u c o m m a n d o p e n s the Preferences dialog box,
which lets y o u decide the behavior and physical appearance of the T u r b o Pascal
for W i n d o w s environment (see figure 1.13).
Figure 1.13. The Preferences dialog box.
Editor Options
T h e Editor O p t i o n s g r o u p has several check boxes that control text handling in
Edit w i n d o w s . They are
• Create B a c k u p File
• A u t o Indent M o d e
• Use Tab Character
• O p t i m a l Fill
• Backspace Unindents
50. 26 Part I—Working with TPW
• Cursor through Tabs
• G r o u p U n d o
• Block Overwrite
T h e A u t o Save options define w h e n and h o w often T u r b o Pascal for
W i n d o w s saves your o p e n files, settings, and options. They are
• Editor Files
• D e s k t o p
• Configuration
W h e n y o u select a n e w font displayed in the list box, the Font list b o x
changes the size and appearance of the text.
T h e Tab Size input b o x controls the n u m b e r of c o l u m n s the cursor moves
for each tab stop.
T h e Right M o u s e Button options (Nothing and Topic Search) determine
whether T u r b o Pascal for W i n d o w s uses the right button to initiate a topic
search in H e l p .
The C o m m a n d Set options ( C U A or Alternate) determine whether the
editor uses C o m m o n User Access (CUA) c o m m a n d s or Alternate c o m m a n d s .
Open
T h e Options/Open c o m m a n d displays the O p e n Configuration File dialog box,
where y o u can retrieve n e w configuration-file settings. T h e File N a m e input b o x
lets y o u enter the n a m e of the configuration file containing the settings y o u
want; y o u choose O K or press Enter to load that file. T h e default configuration
file n a m e is T P W . C F G .
T h e Files list b o x lists the names of files in the current directory that match
the file-name mask in the File-Name input box.
The Directories list b o x lets y o u select a different directory to view. Press
Alt-D to place the cursor in this list box.
Save
T h e Options/Save c o m m a n d saves in the current configuration file the primary
file n a m e , the settings you selected with the O p t i o n s m e n u , and the desktop
setup.
Use Options/Save As to save options to a different configuration file. T h e
n a m e of the current configuration file appears next to the Options/Save
c o m m a n d .
• All options and the editor c o m m a n d table are stored in T P W . C F G , the
default saved-options file.
51. 1—Getting Started 27
• History lists, the desktop state, and breakpoint locations are stored in
TPW.INI.
Save As
T h e Options/Save As c o m m a n d o p e n s t h e Configuration Save As dialog box,
where y o u enter a n e w n a m e for your configuration file (see figure 1.14).
Figure 1.14. The Configuration Save As dialog box.
Y o u can create a n e w configuration file by setting options a n d then
selecting Options/Save As and entering a n e w configuration file n a m e . T h e
newly created configuration file is n o w in effect.
In the File N a m e input box, enter a n e w n a m e for the configuration file.
C h o o s e O K or press Enter to create a . C F G file with the n e w n a m e .
If y o u d o not specify a file extension, T u r b o Pascal for W i n d o w s adds a
. C F G extension for y o u . For example:
YOUR becomes YOUR.CFG.
A history list is attached to the File N a m e input box. If the Configuration
option is o n , settings m a d e to the current configuration file are saved w h e n
y o u exit.
52. 28 Parti—Working with TPW
Directories List Box
Use the Directories list b o x to change to another directory. Press Alt-D to place
the cursor in the Directories list box.
The Window Menu
T h e Window m e n u has c o m m a n d s for manipulating and o p e n i n g windows.
Most of the windows y o u o p e n from this m e n u have the standard w i n d o w
elements such as scroll bars, Minimize and Maximize buttons, and a Control
m e n u box.
O p e n windows with the File/Open or File/New c o m m a n d s .
At the bottom o f the Window m e n u is a list of o p e n windows. If more than
o n e w i n d o w is o p e n , y o u can switch to another w i n d o w and make it active by
selecting it from the list.
These are the Window m e n u c o m m a n d s :
• Tile
• Cascade
• Arrange Icons
• Close All
Tile
C h o o s e Window/Tile to tile your o p e n windows. Using this c o m m a n d arranges
the windows so that they cover the entire desktop without overlapping o n e
another.
Cascade
C h o o s e Window/Cascade to stack all o p e n Edit windows. Cascade overlaps
o p e n windows so that each w i n d o w is the same size, but part of each underlying
w i n d o w is visible.
Arrange Icons
Select Window/Arrange Icons to rearrange the icons.
Rearranged icons are evenly spaced, beginning at the lower-left corner o n
the desktop. T h e o p e n files must be Minimized or this c o m m a n d is disabled.
53. 1—Getting Started 29
Close All
C h o o s e Window/Close All to close all o p e n w i n d o w s o n the desktop. If the text
was changed since the previous time y o u saved it, a dialog b o x warns y o u to save
the file before closing the window. C h o o s e Yes, N o , or Cancel.
The Help Menu (Alt-H)
T h e H e l p m e n u provides access to on-line H e l p , which appears in a special H e l p
w i n d o w . T h e H e l p system provides information about most aspects o f the
integrated environment and Turbo Pascal for Windows. T h e following list
shows the H e l p m e n u c o m m a n d s :
• I n d e x
• Topic Search
• Using H e l p
• Compiler Directives
• ObjectWindows
• Procedures and Functions
• Reserved Words
• Standard Units
• Turbo Pascal for Windows Language
• Windows API
• About Turbo Pascal for Windows
Index (Shift-Fl)
Turbo Pascal for Windows' on-line H e l p c o m e s with a comprehensive index
that summarizes the organization and contents of the H e l p system. T o get into
the H e l p system from the index, select o n e of the highlighted words or phrases
in the index, click it or Tab to it, and then press Enter.
If y o u don't k n o w how to use a H e l p system u n d e r Windows, choose the
Help/Using H e l p M e n u c o m m a n d .
Topic Search (Ctrl-Fl)
If y o u place your cursor o n a word (a "token") in the active Edit w i n d o w and
choose Help/Topic Search, a H e l p w i n d o w o p e n s with information about that
token.
54. 30 Parti—Working with TPW
Y o u can set u p the Right m o u s e button (in the Options/Preferences dialog
box) to initiate a topic search.
H e l p provides on-line reference for many elements of the T u r b o Pascal for
W i n d o w s language, including functions and procedures, reserved words,
global variables, ObjectWindows, the W i n d o w s API, and so o n .
Help/Using Help
T h e Help/Using H e l p c o m m a n d displays information o n h o w to use T u r b o
Pascal for W i n d o w s ' H e l p system (or any other H e l p system u n d e r W i n d o w s ) .
Compiler Directives
W h e n y o u choose this m e n u c o m m a n d , y o u see an index of compiler directives.
C o m p i l e r directives control s o m e of T u r b o Pascal for W i n d o w s ' features.
• S o m e turn compiler features o n or off.
• S o m e specify parameters that affect h o w your application program is
compiled.
• Others control the conditional compilation of your application.
A compiler directive is a c o m m e n t with a special syntax that y o u can put
anywhere a c o m m e n t is allowed.
ObjectWindows
W h e n y o u select this m e n u c o m m a n d , y o u see a hierarchy of ObjectWindows
types.
Procedures and Functions
W h e n y o u choose this m e n u c o m m a n d , y o u see an index of the T u r b o Pascal
for W i n d o w s library procedures and functions that y o u can use to develop
applications.
Reserved Words
W h e n y o u select this m e n u c o m m a n d , y o u see an index of all the reserved words
in the T u r b o Pascal for W i n d o w s language. Reserved words have special
m e a n i n g to the compiler. D o not use a reserved w o r d to n a m e your variables,
procedures, functions, objects, and so o n .
55. 1—Getting Started 31
Standard Units
W h e n y o u select this m e n u c o m m a n d , y o u see a n index o f T u r b o Pascal for
W i n d o w s ' standard units. A standard unit is a collection o f predefined con-
stants, data types, variables, procedures, a n d functions. Y o u tell your applica-
tion program to u s e only the units it needs.
Turbo Pascal for Windows Language
W h e n y o u select this m e n u c o m m a n d , y o u see a list o f the elements that
comprise the T u r b o Pascal for W i n d o w s language.
Windows API
W h e n y o u select this m e n u c o m m a n d , y o u see an index of the constants, styles,
messages, types, functions, a n d procedures that comprise the W i n d o w s Appli-
cation Programming Interface (API). T u r b o Pascal for W i n d o w s declares all the
W i n d o w s styles, constants, a n d types in the WinTypes unit. T h e WinProcs unit
has all the API procedures a n d functions.
About Turbo Pascal for Windows
W h e n y o u select this c o m m a n d , a dialog b o x appears with copyright a n d
version information.
Press Esc o r click O K or Cancel to close the b o x .
Editor
T h e T u r b o Pascal for W i n d o w s editor is a complete programming editor. In
almost all cases, y o u use it to develop all facets of your applications. In addition
to being a full-screen, command-rich editor, it is based o n W i n d o w s ' multi-
d o c u m e n t interface, which y o u learn h o w to use in Chapter 7, "Many Windows:
A Multi-Document Interface." T h e multi-document interface enables many files
to b e o p e n simultaneously. Thus, y o u c a n o p e n files for several units a n d switch
between them easily without closing any files—a great feature w h e n y o u
develop large projects.
The Editor Commands
T u r b o Pascal for W i n d o w s ' editor c o m m a n d s are summarized in the following
groups o f c o m m a n d s :
56. 32 Part I—Working with TPW
• Block c o m m a n d s
• Block c o m m a n d s ( C U A and Alternate)
• Block c o m m a n d s (Borland style)
• Extending selected blocks
• O t h e r c o m m a n d s
• Cursor-movement c o m m a n d s
• Insert and Delete c o m m a n d s
• M o r e about editor c o m m a n d s
• Miscellaneous keyboard c o m m a n d s
The Block Commands
T h e following sections describe the block c o m m a n d s .
Copy Block
This c o m m a n d copies a previously selected block to the Clipboard and pastes
it to the current cursor position. T h e original block is u n c h a n g e d . If n o block
is selected, nothing h a p p e n s .
Copy Text
This c o m m a n d copies selected text to the Clipboard. Press Ctrl-Ins to use the
c o m m a n d .
Cut Text
This c o m m a n d s cuts selected text to the Clipboard. Press Shift-Del to use the
c o m m a n d .
Delete Block
This c o m m a n d deletes a selected block. Y o u can "undelete" a block with U n d o .
Press Ctrl-Del or Ctrl-KY to use this c o m m a n d .
Move Block
This c o m m a n d moves a previously selected block from its original position to
the Clipboard and then pastes it to the cursor position. T h e block disappears
from its original position. If n o block is marked, nothing h a p p e n s . Press Shift-
D e l to m o v e text to Clipboard and Shift-Ins to paste text in current d o c u m e n t .
57. 1—Getting Started 33
PastefromClipboard
This c o m m a n d pastes t h e contents of t h e Clipboard to cursor location. Press
Shift-Ins to use t h e c o m m a n d .
Read BlockfromDisk
This c o m m a n d reads a disk file into t h e current text at t h e cursor position
exactly as t h o u g h it was a block. Press Shift-Ctrl-R or Ctrl-KR to use this
c o m m a n d .
T h e text read is then selected as a block. When this c o m m a n d is initiated,
y o u are p r o m p t e d for t h e n a m e of t h e file to read. Y o u can use wildcards to
select a file to read, and a directory is displayed. T h e file specified can be any
legal file n a m e .
WWte Block to Disk
This c o m m a n d writes a selected block to a file. Press Shift-Ctrl-W or Ctrl-KW to
use this c o m m a n d . When y o u specify this c o m m a n d , T u r b o Pascal for Windows
prompts y o u for t h e n a m e of t h e file to write to. T h e file can be given any legal
n a m e (the default extension is .PAS). If y o u prefer to use a file n a m e without an
extension, a p p e n d a period to t h e e n d of its n a m e .
Note: If the file specified already exists, a warning is issued before t h e
existing file is overwritten. If n o block is selected, nothing happens.
Editor-Command Tables
T h e tables throughout this section list t h e editor c o m m a n d s and their function
or meaning.
Table 1.1. The Block commands (CUA and Alternate).
Movement CUA Both Alternate
Delete block Ctrl-Del Ctrl-Del
C o p y to Clipboard Ctrl-Ins Ctrl-Ins
C u t to Clipboard Shift-Del Shift-Del
Paste from Clipboard Shift-Ins Shift-Ins
Read block from disk Shift-Ctrl-R Ctrl-KR
Write block to disk Shift-Ctrl-W Ctrl-KW
Indent block Shift-Ctrl-I Ctrl-KI
Unindent block Shift-Ctrl-U Ctrl-KU
58. 34 Parti—Working with TPW
Table 1.2. The Block commands (Borland style).
Command Keys Function
Text selection O n Ctrl-KB Begins the selection of text;
text selection ends with
copying (Ctrl-KK) or cutting
(Ctrl-KV) to the Clipboard, or
turning text selection off with
Ctrl-KH
Text selection Off Ctrl-KH Stops the selection of text, and
the selected text b e c o m e s
unselected
C o p y text to Clipboard Ctrl-KK C o p i e s the selected text to the
Clipboard
C u t text to Clipboard Ctrl-KV Cuts the selected text to the
Clipboard
Paste from Clipboard Ctrl-KC Pastes the contents of the
Clipboard into your active Edit
w i n d o w
Extending selected blocks
Movement CUA Both Alternate
Left 1 character Shift-Left Shift-Left
Right 1 character Shift-Right Shift-Right
End of line Shift-End Shift-End
Beginning of line Shift-Home Shift-Home
Same column, Shift-Down Shift-Down
next line
Same column, Shift-Up Shift-Up
previous line
O n e page d o w n Shift-PgDn Shift-PgDn
O n e page u p Shift-PgUp Shift-PgUp
Left o n e word Shift-Ctrl-Left Shift-Ctrl-Left
Right o n e word Shift-Ctrl-Right Shift-Ctrl-Right
End of file Shift-Ctrl-End Shift-Ctrl-End Shift-Ctrl-PgDn
Beginning of file Shift-Ctrl-Home Shift-Ctrl-Home Shift-Ctrl-PgUp
59. 1—Getting Started 35
N o t e : T u r b o Pascal for Windows' Borland-style block c o m -
m a n d s work only with t h e Alternate c o m m a n d set.
Table 1.3- Commands that extend selected blocks.
Movement CUA Both Alternate
Left 1 character Shift-Left Shift-Left
Right 1 character Shift-Right Shift-Right
E n d o f line Shift-End Shift-End
Beginning o f line Shift-Home Shift-Home
Same c o l u m n , Shift-Down Shift-Down
next line
Same c o l u m n , Shift-Up Shift-Up
previous line
O n e page d o w n Shift-PgDn Shift-PgDn
O n e page u p Shift-PgUp Shift-PgUp
Left o n e w o r d Shift-Ctrl-Left Shift-Ctrl-Left
Right o n e w o r d Shift-Ctrl-Right Shift-Ctrl-Right
E n d o f file Shift-Ctrl-End Shift-Ctrl-End Shift-Ctrl-PgDn
Beginning o f file Shift-Ctrl-Home Shift-Ctrl-Home Shift-Ctrl-PgUp
Table 1.4. The cursor-movement commands (CUA and Alternate).
Movement CUA Both Alternate
Character left Left Left Ctrl-S
Character right Ctrl-Right Right Ctrl-D
W o r d left Ctrl-Left Ctrl-Left Ctrl-A
Scroll d o w n 1 line Ctrl-Z Ctrl-Z Ctrl-Z
Line u p U p U p Ctrl-E
Line d o w n D o w n D o w n Ctrl-X
Scroll u p 1 line Ctrl-W Ctrl-W Ctrl-W
Scroll d o w n 1 line Ctrl-Z Ctrl-Z Ctrl-Z
Page u p P g U p P g U p Ctrl-R
continues
60. 36 Parti—Working with TPW
Table 1.4. continued
Movement CUA Both Alternate
Page d o w n P g D n P g D n Ctrl-C
Last cursor position Ctrl-QP
Beginning of line H o m e H o m e Ctrl-QS
E n d of line E n d E n d C t r l - Q D
T o p of w i n d o w Ctrl-E Ctrl-QE
B o t t o m of w i n d o w Ctrl-X Ctrl-QX
T o p of file Ctrl-Home Ctrl-Home Ctrl-QR, Ctrl-PgUp
B o t t o m of file Ctrl-End Ctrl-End C t r l - Q C , Ctrl-PgDn
Table 1.5- The Insert and Delete commands (CUA and Alternate).
Movement CUA Both Alternate
Delete char D e l Ctrl-G
Delete char to left Backspace Backspace
Delete line Ctrl-Y Ctrl-Y
Delete line e n d Shift-Ctrl-Y Ctrl-QY
Delete w o r d Ctrl-T
Insert line Ctrl-N Ctrl-N
Insert m o d e On/Off Ins Ins Ctrl-V
Auto Indent
This c o m m a n d toggles the automatic indenting of successive lines. Y o u also can
use Options/Preferences/Autolndent in the I D E to turn automatic indenting o n
and off.
Current Compiler Options
Inserts the current compiler-option settings at the head of your active Edit
w i n d o w .
Cursor through Tabs
T h e arrow keys m o v e the cursor to the middle of tabs w h e n this option is o n ;
otherwise the cursor w o u l d j u m p several c o l u m n s w h e n it moves over multiple
tabs. Ctrl-OR is a toggle.
61. 1—Getting Started 37
Find Place Marker
This c o m m a n d finds a m a x i m u m of ten place markers (N can be any n u m b e r in
the range zero to nine) in text. M o v e the cursor to any previously set marker by
pressing Ctrl-Q and the marker number.
Open File
O p e n s an existing file in an Edit w i n d o w .
Optimal Fill
O p t i m a l Fill begins every line with the m i n i m u m n u m b e r of characters possible,
using Tabs and spaces as necessary. This option produces lines with fewer
characters.
Save File
This c o m m a n d saves the file and returns to the editor.
Set Place
This c o m m a n d marks a m a x i m u m of ten places in text w h e n y o u press Ctrl-K,
followed by a single-marker digit (zero to nine). After marking your location,
y o u can w o r k elsewhere in the file and then return to a marked location by using
the Find Place Marker c o m m a n d (be sure to use the same marker n u m b e r ) . Y o u
can have as many as ten places marked in each w i n d o w .
Show last Compile Error
This c o m m a n d highlights the last syntax error that the compiler f o u n d during
the previous compile. T h e error message appears o n the status bar. If y o u have
already closed that file, T u r b o Pascal for W i n d o w s reopens it and highlights the
error.
Tab Mode
Y o u can specify the use of true Tab characters in the I D E with the Options/
Preferences/Use Tab Character option.
Unindent
Y o u can turn Unindent o n and off from the I D E with the Options/Preferences/
Backspace Unindents option.
62. 38 Parti—Working with TPW
Table 1.6. Miscellaneous keyboard commands.
Movement CUA Both Alternate
Autoindent on/off Ctrl-OI
C o m p i l e r options C t r l - O O
Cursor through Tabs Ctrl-OR
on/off
Find place marker N Ctrl-N* Ctrl-Q-N*
H e l p F l F l
H e l p index Shift-Fl Shift-Fl
Maximize w i n d o w F5
O p e n file F3
Optimal fill m o d e Ctrl-OF
on/off
Pair matching Alt-[, Alt-] Ctrl-Q [, Ctrl-Q ]
Save file F2, Ctrl-KJ
Search Ctrl-QF
Search again F3 F3
Search and replace Ctrl-QA
S h o w last compile Ctrl-QW
error
Set marker Shift-Ctrl-N* Ctrl-K-N*
Tabs m o d e on/off Ctrl-OT
Topic H e l p Ctrl-Fl Ctrl-Fl
Exit Alt-F4 Alt-X
U n d o Alt-Backspace Alt-Backspace
Unindent m o d e Ctrl-OU
on/off
Insert control Ctrl-P ** Ctrl-P **
character
* TV indicates a number from zero to nine.
r
* To enter a control character, first enter Ctrl-P, and then enter the control character.
The TPW Command-line Compiler
The T u r b o Pascal for W i n d o w s command-line compiler (TPCW.EXE) lets y o u
invoke all the functions of the I D E compiler (TPW.EXE) from the D O S
c o m m a n d line.
63. 1—Getting Started 39
T u r b o Pascal for W i n d o w s command-line options use this syntax:
TPCW [ o p t i o n s ] < f i l e name> [ o p t i o n s ]
where [ o p t i o n s ] can be o n e or m o r e options, separated by spaces. Y o u
designate the status of the compiler option by specifying a plus ( + ) or a minus
(-) after the option.
• Place a + (or a space) after an option to turn it O n .
• Place a - after the option to turn it Off.
Table 1.7. Compiler options.
Option Meaning
Directive options
/$A Align data
/$B B o o l e a n evaluation
/$D D e b u g information
/$F Force FAR calls
/$G Generate 286 instructions
/$! Input/Output checking
/$L Local Symbol information
/$N 80x87 C o d e (numeric coprocessor)
/$R Range checking
/$S Stack-overflow checking
/$V String variable checking
/$W Windows stack frame
/$X Extended syntax
Mode options
/B Build all
/F Find error
/L Link buffer
/M Make
/Q Quiet (no I D E equivalent)
Conditional defines option
/D Conditional defines
continues
64. 40 Parti—Working with TPW
Table 1.7. continued
Option Meaning
Debug options
/G .MAP file
/V D e b u g information in E X E option
Directory options
/E E X E and T P U directory
/I Include directories
/O Object Files directories
/R Resource directories
/T T u r b o directory
/U Unit directories
Most of the command-line options have equivalent m e n u c o m m a n d s .
Table 1.8. Command-line options and their IDE equivalents.
Option IDE Equivalent
/$A Options/Compiler/Align data
/$B Options/Compiler/Boolean evaluation
/$D Options/Compiler/Debug information
/$¥ Options/Compiler/Force far calls
/$G Options/Compiler/286 c o d e
/$! Options/Compiler/I/O checking
/$L Options/Compiler/local symbols
/$M Options/Compiler/Memory sizes
/$N Options/Compiler/80x87 code
/$R Options/Compiler/Range checking
/$S Options/Compiler/Stack checking
/$V Options/Compiler/String Variable C h e c k i n g O p t i o n s
/$W Options/Compiler/Windows Stack Frames
/$X Options/Compiler/Extended Syntax
/B Compile/Build
65. 1—Getting Started 41
Option IDE Equivalent
ID Options/Compiler/Conditional Defines
IE Options/Directories/EXE and T P U Directory
/F Search/Find Error
/G Options/Linker/Map File
/I Options/Compiler/lnclude Directories
IL Options/Linker/Link Buffer
/M Compile/Make
/O Options/Directories/Object Directories
/Q (none)
/R Options/Directories/Resource Directories
IT (none)
/U Options/Directories/Unit Directories
/V Options/Linker/Debug Information in E X E
Onward, Forward, and Upward
T u r b o Pascal for W i n d o w s is a flexible, powerful application development
environment for Microsoft Windows, complete with editor, compiler, debugger,
linker, and a powerful library of objects and tools. Y o u don't have to be a
W i n d o w s or T u r b o Pascal expert to use T u r b o Pascal for W i n d o w s ; instead it
helps y o u b e c o m e the W i n d o w s expert.
A T u r b o Pascal for W i n d o w s application is limited only by your imagina-
tion. Y o u can use units and libraries to create large and powerful W i n d o w s
applications using either the I D E or the command-line compiler.
In the next few h u n d r e d pages, I'll s h o w y o u just h o w easy and fun it can
be to create W i n d o w s applications T u r b o Pascal style, using the p o w e r and
flexibility of object-oriented programming techniques. S o u n d easy? It is. In the
next chapter, y o u will g o to it!
66.
67. 2
CHAPTER
ELEMENTS OF APPLICATION
DEVELOPMENT
Your Windows program doesn't interact directly with the screen, keyboard,
printer, or any other device. Windows does all that, and places the results in
an application message queue (in a device-independent fashion).
Lee and Mark Atkinson
If y o u have p r o g r a m m e d in any language, y o u undoubtedly have your o w n ideas
about h o w to develop an application, whether it is for W i n d o w s or otherwise.
T o develop an application for W i n d o w s , y o u have to learn h o w W i n d o w s works,
but only at an easy level. Y o u also have to prepare your application to run in a
W i n d o w s w i n d o w and y o u have to think (at least somewhat) in terms of events.
T h e beans and rice of a W i n d o w s application is what y o u are used to: c o d e for
solving p r o b l e m s — c o d e that manipulates information (or data).
T h e biggest difference between developing a D O S application and a
W i n d o w s application is that, with D O S , y o u are required to create your o w n
user interface (unless y o u are writing a primitive application or o n e that does
not require an interface). If y o u are writing a W i n d o w s application, y o u must
"connect" to the W i n d o w s G U I (graphical user interface), but y o u d o not have
to create it. Y o u use the W i n d o w s Interface, and y o u continue to use most of
what y o u already k n o w about programming.
68. 44 Part I—Working with TPW
T o use a W i n d o w s application to solve a problem, y o u have to
1. Interact with W i n d o w s (mostly using ObjectWindows).
2. G e t information into the application (the input c o m p o n e n t ) .
3. Store information (the data c o m p o n e n t ) .
4. Manipulate the information, using procedures, functions, or object
m e t h o d s (the operations c o m p o n e n t ) .
5. G e t the results (the output c o m p o n e n t ) .
These steps are straightforward and probably familiar to y o u , except for
the W i n d o w s connection. T o connect with W i n d o w s , use ObjectWindows, the
T u r b o Pascal for W i n d o w s O O P library. ObjectWindows is an object-oriented
library, packaged with T u r b o Pascal for W i n d o w s , that greatly simplifies
W i n d o w s applications development by encapsulating (packaging) c o m p l e x
W i n d o w s information in a simpler, m o r e easily accessible form.
T o handle actions 2 through 5, y o u structure your application along
traditional "structured" programming lines. Y o u use conditional statements
( I t s ) and loops ( w h i l e s , r e p e a t s , and so o n ) . Y o u divide groups of instructions
into sections that can be referenced by n a m e (procedures, functions, objects).
This again is programming as y o u probably already k n o w it (whether y o u
program in Pascal or another similarly structured language such as C or C + + ).
T u r b o Pascal for W i n d o w s , like T u r b o Pascal for D O S , supplies a rich set
of data types and built-in operators, controls, procedures, and functions for
manipulating information. T u r b o Pascal for W i n d o w s lets y o u create large
applications by dividing any program (or application) into pieces (units) that
can be compiled separately.
T h e remainder of this chapter briefly covers s o m e of the basic aspects of
T u r b o Pascal for W i n d o w s and its development capabilities. If y o u already k n o w
T u r b o Pascal, feel free to skip this section and m o v e o n to the next chapter,
where y o u learn h o w to develop W i n d o w s applications using the object-
oriented techniques of ObjectWindows. (You will not see any Windows-specific
c o d e until the next chapter.) If y o u want m o r e information about the standard
(or built-in) T u r b o Pascal for W i n d o w s procedures and functions, check out the
reference section.
Units
T o develop any T u r b o Pascal for W i n d o w s application, y o u must use at least o n e
T u r b o Pascal for W i n d o w s standard unit, but y o u can use many m o r e units if y o u
have to (either standard ones or units y o u create).
A unit is a collection of constants, data types, variables, procedures, and
functions. In a nutshell, a unit is the basis of m o d u l a r programming in T u r b o
Pascal for D O S and T u r b o Pascal for W i n d o w s . Y o u use units to create libraries
and to divide large applications into logically related m o d u l e s .
69. 2—Elements of Application Development 45
T u r b o Pascal for W i n d o w s supplies the following standard units:
Strings
System
WinCrt
WinDOS
WinProcs
WinTypes
These standard units (which are stored in TPW.TPL) support your T u r b o
Pascal for W i n d o w s applications in m a n y ways, taking m u c h o f the work o u t o f
developing applications.
T h e Strings unit supports a type o f character strings called null-
terminated strings. Null-terminated strings are the type o f strings required by
the W i n d o w s Application Programming Interface (API). (Previously, T u r b o
Pascal did not support null-terminated strings.)
T h e System unit (SYSTEM.TPU) is the T u r b o Pascal for W i n d o w s run-time
library. It implements low-level, run-time support routines (procedures a n d
functions) for all the built-in T u r b o Pascal for W i n d o w s "features," such as file
Input/Output, floating point operations, string-handling, and dynamic m e m o r y
allocation.
All units a n d programs automatically u s e the System unit, so y o u d o not
have to specify it in a uses declaration. (You learn m o r e about the uses
declaration in this section).
T h e WinCrt unit implements a terminal-like text screen in a w i n d o w . Y o u
d o not have to write "Windows-specific" c o d e if your application uses WinCrt.
In many cases, y o u c a n start with T u r b o Pascal for W i n d o w s quickly by
translating existing T u r b o Pascal (for D O S ) c o d e a n d using the WinCrt screen
to "run" it. Y o u will learn h o w to use WinCrt in the next chapter.
T h e WinDos unit implements operating system a n d file-handling proce-
dures a n d functions. These procedures a n d functions are specific to T u r b o
Pascal a n d are not defined by standard Pascal.
T h e WinProcs unit defines function a n d procedure headers for the
W i n d o w s API. Y o u c a n access every function in the standard W i n d o w s libraries
through WinProcs. T h e WinProcs a n d WinTypes units both define the T u r b o
Pascal for W i n d o w s implementation o f the W i n d o w s API.
T h e WinTypes unit defines T u r b o Pascal versions o f all the types used by
the W i n d o w s API functions, including simple types and data structures (records,
a n d so o n ) a n d all the standard W i n d o w s constants, including flags, messages,
a n d styles.
Units are both conceptually a n d pragmatically important because
• They are precompiled s o y o u c a n u s e the functions, procedures, a n d
so o n in a unit without recompiling the unit each time y o u compile
another part o f your application. T h u s , units save time.
70. 4 6 Part I—Working with TPW
• Units also let y o u break u p functionality for separate development,
modification, a n d use. Projects thus can b e large a n d their develop-
ment a n d management simplified.
Units are nifty, useful structures that change the way your T u r b o Pascal for
Windows application code is stored in memory. Consider first h o w a compiled
T u r b o Pascal for W i n d o w s application (without units) stores itself in memory.
It divides itself into four main sections:
1. Code segment
2. D a t a segment
3. S t a c k segment
4. H e a p
The code segment contains the application's procedures, functions, a n d
the main program b o d y o f the application. T h e d a t a segment contains the
application's global variables a n d constants. T h e s t a c k segment contains
return addresses for the applications' functions a n d procedures a n d most of the
local variables declared inside functions a n d procedures. T h e heap contains
any variables y o u create dynamically using the T u r b o Pascal for W i n d o w s
keyword, New.
Each section (code, d a t a , a n d s t a c k segments) can use as m u c h as 64K
(kilobytes) of memory, a n d the heap can grow as large as available m e m o r y
allows. Figure 2.1 shows a m e m o r y m a p of this scheme.
High Memory
Heap ?K
Stack Segment 64K
Data Segment 64K
Code Segment 64K
Memory Map
Without units
Low Memory
Figure 2.1. A memory map of three segments, plus the heap.
71. 2—Elements of Application Development 47
Without units, a compiled T u r b o Pascal for Windows application can be
about 192K plus the h e a p (whose size d e p e n d s o n the n u m b e r of dynamically
allocated variables).
In contrast, the procedures and functions in a unit are stored in separate
segments apart from the m a i n m o d u l e . Each unit can use as m u c h as 64K of
memory. T h u s , an application that uses units can consist of as m a n y of these 64K
units as m e m o r y (the system's, not yours) allows. O f course, applications that
use units can be large. Figure 2.2 shows a m e m o r y m a p of an application
segmented into units.
High memory
Heap
?K
Stack Segment 64K
Data Segment 64K
Unit 64K
Unit 64K
Code Segment
64K
Low memory
M e m o r y Map
with units
Figure 2.2. A memory map of units.
T o use a standard (or precompiled) unit, add a u s e s declaration at the
beginning of the main m o d u l e of your application:
Program M a i n ;
u s e s
W i n C r t ;
{ . . . . body h e r e . . . }
T o use m o r e than o n e unit, separate the units by c o m m a s :
Program M a i n ;
u s e s
W i n T y p e s ,
S t r i n g s ,
72. 48 Parti—Working with T P W
WinProcs,
WObjects;
{ ... body here ... }
Y o u use the standard T u r b o Pascal for W i n d o w s units throughout this
b o o k , a n d they are discussed in m o r e detail as y o u m o v e along.
Creating your o w n units is similar to creating the main m o d u l e o f a n
application, with a couple o f exceptions:
1. Rather than designate the m o d u l e as a program, y o u designate it as a
unit:
Unit YourUnit;
2. Y o u also divide the unit into parts:
Unit heading
Interface part
Implementation part
Initialization part
T h e unit heading specifies the unit's n a m e (the n a m e y o u u s e w h e n y o u
refer to this unit in another module's Uses declaration).
T h e interface part declares constants, types, variables, procedures, a n d
functions that are public (available to any m o d u l e that uses the unit). List the
procedures a n d functions as headings only in the interface part.
T h e implementation part defines the bodies o f all public procedures a n d
functions. I n addition, it declares constants, types, variables, procedures, a n d
functions that are private a n d , thus, are not available to users o f the unit.
T h e initialization part is the last part o f a unit. It consists o f either:
• T h e reserved w o r d end ( n o initialization code)
or
• A statement part to b e executed to initialize the unit
Listing 2.1 shows the layout o f a unit.
Listing 2.1. The general layout of a unit.
Unit YourUnit;
Interface
{
Use something
here
}
73. 2—Elements of Application Development 49
{
CONST,
TYPE,
VAR
declarations here
}
{
PROCEDURE and
FUNCTION
declarations here
}
Implementation
{
Another
Use
here, if you want it
}
{
Any Private
LABEL,
CONST,
TYPE,
VAR
declarations here
}
{
Procedure and
function
bodies here
}
Begin
{
Initialization statements
}
End.
74. 50 Part I—Working with TPW
T u r b o Pascal for W i n d o w s handles units intelligently. For example, if
several m o d u l e s (or units) in an application refer to the same unit, only o n e
copy of that unit—not several—is loaded into memory.
Data Types and Identifiers
Application development begins and ends with variables. Whenever y o u
declare a variable, y o u must specify its type. T h e variable type indicates
• T h e range of values the variable can take
• T h e operations that can be performed o n it
W h e n y o u specify a type (in a t y p e declaration) y o u specify an identifier
that denotes a type.
Y o u use identifiers throughout your application, and a T u r b o Pascal for
W i n d o w s identifier can denote any of the following:
• Constants
• Fields in records
• Functions
• Labels
• Procedures
• Programs
• Types
• Units
• Variables
Identifiers can be any length, but only the first 63 characters are significant
(recognized by T u r b o Pascal for W i n d o w s ) .
Y o u have to follow a few rules w h e n y o u use identifiers:
• T h e first character of an identifier must be a letter.
• T h e characters that follow the first character must be letters, digits, or
underscores (no spaces).
• Identifiers are not case-sensitive.
As this chapter states, applications development begins and ends with
variables. Variables must be t y p e d in T u r b o Pascal. It is helpful to divide these
types into six major classes, which are covered next. For m o r e in-depth
information about T u r b o Pascal for W i n d o w s types, consult the T u r b o Pascal for
W i n d o w s manuals.
75. 2—Elements ofApplication Development 51
Qualified Identifiers
W h e n your application declares several instances of the same identi-
fier, you might have to qualify the identifier by specifying a unit
identifier to select the correct instance of the identifier.
The combined Unit. Identifier specification is called a qualified
identifier.
For example, the following are qualified identifiers:
System. Exit (unit = System, identifier = Exit)
Dos. Exec (unit = Dos, identifier = Exec )
Crt .Window ( unit = Crt, identifier = Window)
Y o u c a n divide types as follows:
1. Simple types that define ordered sets o f values:
A. Ordinal types, which include:
Integer types
B o o l e a n types
Char type
Enumerated types
Subrange types
B. Real types
2. String types that represent a sequence o f characters with a dynamic
length attribute a n d a constant size attribute.
3. Structured types that hold more than o n e value. These include:
Array types
Record types
Object types
Set types
File types
4. Pointer types that define a set o f values that point to dynamic variables
of s o m e type. A dynamic variable is o n e that is allocated o n the heap
and manipulated using pointers. Because the heap c a n b e quite large
(much larger than a stack allocated in the data segment, which is
limited to 64K), dynamic variables also c a n b e quite large.
5. Procedural types that allow procedures a n d functions to b e treated as
objects. A n object, which y o u learn m u c h more about throughout this
76. 52 Part I—Working with TPW
b o o k , consists of data and the procedures and functions that y o u use
to manipulate that data. For example:
AWindow = object
x1, x2, y1, y2 :Integer;
procedure minimize;
procedure maximize;
end;
6. Object types are structures that consist of a fixed n u m b e r of c o m -
ponents.
Ordinal Types
T u r b o Pascal has nine predefined ordinal types. Five of these integer types
denote a specific subset of the w h o l e numbers:
Type Range Size
Shortint 128.. 127 8-bit
Integer - 3 2 7 6 8 . 3 2 7 6 7 16-bit
Longint -2147483648. .2147483647 32-bit
Byte 0.255 8-bit
Word 0.65535 16-bit
T h e other four predefined ordinal types are the Booleans ( B o o l e a n ,
WordBool, L o n g B o o l ) , a n d C h a r .
T w o other classes of user-defined ordinal types are enumerated types and
subrange types.
Three standard functions can b e u s e d with all ordinal types:
1. Ord (which returns the ordinality of the value). For example:
O r d ( F a l s e ) = 0;
2. Pred (which returns the predecessor of the value). For example:
P r e d ( T r u e ) = F a l s e ;
3. S u c c (which returns the successor of the value). For example:
S u c c ( T r u e ) = F a l s e ;
Boolean Types
T u r b o Pascal for W i n d o w s has three predefined B o o l e a n types: B o o l e a n ,
WordBool, and L o n g B o o l , which are defined as follows:
77. 2—Elements of Application Development 5 3
type
Boolean = (False, True);
WordBool = (False, True);
LongBool = (False, True);
These types have the following sizes:
• Boolean is byte-sized (8 bits).
• WordBool is word-sized (16 bits).
• LongBool is longint-sized (32 bits).
Because Booleans are enumerated ordinal types, the following relation-
ships exist a m o n g B o o l e a n types:
True > False
Ord(False) = 0
Ord(True) = 1
Succ(False) = True
Pred(True) = False
A m o n g the "Booleans," Boolean is the preferred type a n d uses the least
memory. WordBool a n d LongBool exist primarily for compatibility with your
applications in the W i n d o w s environment.
In a n expression, the following relational operators produce results o f
type Boolean:
<>
>
<
> =
< =
IN
For W i n d o w s compatibility, Booleans c a n assume ordinal values other
than zero a n d o n e . A B o o l e a n expression is considered false w h e n its ordinal
value is zero, a n d true w h e n its ordinal value is nonzero.
Char Type
Use variables of the ordinal type Ch a r to store A S C I I characters. Write character
constants between single quotations, as in the following:
78. 54 Part I—Working with T P W
' 9 '
'A'
'L'
'i'
'&'
T h e single quotation character is written as t w o single quotations within
single quotations, like this:
i i i i
T h e Chr function converts a n integer value into a character with the
corresponding A S C I I value.
T h e Ord function returns a character's A S C I I value.
Enumerated Types
Enumerated types define ordered sets of values by enumerating the identifiers
that denote the values. Their ordering is determined by the sequence in which
the identifiers are enumerated.
For example:
type
Food = (Apple, Kiwi, Peach, Date);
In this declaration, Kiwi is a constant o f type Food.
T h e Ord standard function returns the ordinality o f an enumerated
constant. In this example:
Ord (Apple) = 0
Ord(Kiwi) = 1
Ord(Peach) = 2
Ord(Date) = 3
T h e identifiers in the type definition b e c o m e constants of the enumerated
type.
T h e first constant has an ordinality o f zero, the second has a n ordinality
of o n e , the third a n ordinality o f two, a n d so o n .
Subrange Types
A subrange type is a range of values from a n ordinal type sometimes called the
host type.
For example:
LittleConstant .. BiggerConstant
79. 2—Elements of Application Development 5 5
specifies the smallest and largest value in the subrange. In this case, the
subrange is from L i t t l e C o n s t a n t to B i g g e r C o n s t a n t .
Both constants must be of the same ordinal type, and the first constant
must be less than or equal to the second constant.
T h e $R compiler directive controls range-checking of subrange types. T h e
following are subrange examples:
0. .49
-128..127
Reals
A real type has a set of values that is a subset of the real numbers, which can be
represented in floating-point notation with a fixed n u m b e r of digits.
A value's floating-point notation normally consists of three values: M, B,
and E, such that M x B E = N where B is always 10, M is a rational number, and
E is an integer in the real type's range.
Turbo Pascal for Windows supplies four predefined real types. Each type
has a specific range and precision:
Type Range Digits Bytes
Real 2.9e-39..1.7e38 11-12 6
Single 1.5e-45..3.4e38 7-8 4
D o u b l e 5.0e-324..1.7e308 15-16 8
Extended 3.4e-4932..1.1e4932 19-20 10
N o t e : T u r b o Pascal for W i n d o w s supports two models of
floating-point c o d e generation:
1. Software floating point
2. 80x87 floating point
Use the $N compiler directive to switch between the two
models.
Strings
A T u r b o Pascal string type variable (not a null-terminated string type) is a
sequence of characters with a dynamic length, and a constant m a x i m u m size
between 1 and 255.
80. 56 Parti—Working with T P W
If y o u declare a string without a m a x i m u m size, it automatically b e c o m e s
a size o f 255.
String constants are written in quotations; for example:
'Windows1
'Bible'
Notice that two consecutive single quotations are used to indicate a single
quotation in a string.
T h e following operators c a n b e used with string type values:
+
<
>
< =
> =
Operators compare strings by using the A S C I I codes for letters a n d
numbers. For example, the A S C I I c o d e for Af is 77 a n d 7* is 84. Thus, a string
beginning with an M is less than o n e beginning with a T. T h e A S C I I c o d e for a
lowercase ra, however, is 109. Thus, an uppercase 7*is less than a lowercase m.
K e e p this in m i n d w h e n y o u compare strings.
Structured Types
A structured type can hold more than o n e value. Structured types are
• Array (types)
• File (types)
• Object (types)
• Record (types)
• Set (types)
If a c o m p o n e n t type is structured, the resulting structured type has m o r e
than o n e level of structuring a n d can, in fact, have unlimited levels of structur-
ing (memory permitting). In other words, a structured type can contain other
types that are themselves structured. These other types can, in turn, contain
m o r e types that also are structured.
The m a x i m u m size of any structured type in T u r b o Pascal is 65,520 bytes
(about 64K). T h e reserved w o r d packed in a structured type's declaration tells
the compiler to compress data w h e n it stores the type. Note: T u r b o Pascal for
W i n d o w s accepts the reserved w o r d packed, but ignores it.
81. 2—Elements of Application Development 5 7
Arrays
A n array is a collection of values of the same type. Arrays make data m u c h m o r e
manageable.
Y o u declare a n array as follows:
array [index-type] of element-type
T h e element type c a n b e any type, but the index type must b e a n ordinal
type. Y o u c a n use several index types if y o u separate t h e m by c o m m a s . Each
index type separated by a c o m m a represents a dimension o f the array.
For example:
type
CharData = array[1
A'..1
Z1
] of Byte; { 1 Dimension }
NumList = array[1..600] of Integer; { 1 Dimension }
Matrix = array[0..21, 0..21] of real; { 2 Dimensions }
Records
A record contains a n u m b e r o f c o m p o n e n t s , or fields, that c a n b e o f different
types.
A record declaration begins with the keyword record a n d ends with an
end.
For example:
ThisRecord = Record
Month: 0 .. 12;
Day : 1 .. 31;
Year : Integer;
end;
A record also can b e variant. I n other words, a g r o u p o f records c a n have
different structures d e p e n d e n t o n a condition.
For example:
type
ClassType = (Num, Dat, Str);
Date = record
D, M, Y: Integer;
end;
Facts = record
Name: string[10];
82. 58 Parti—Working with T P W
case Kind: ClassType of
Num: (N: real);
Dat: (D: Date);
Str: (S: string);
end;
D e p e n d i n g o n whether Kind is a Num, Dat, or Str, the Facts record
contains an N, D, o r S data field.
Object Types
A n object type is a data structure similar to a record, also containing a fixed
n u m b e r o f c o m p o n e n t s . Each c o m p o n e n t is either a field (which contains data
of a particular type) or a m e t h o d (procedure or function), which "operates" o n
an object's data.
For example:
GenericObject = object
Fieldl : integer; { Object data }
Field2 : real;
procedure Methodl; { Object behavior }
procedure Method2;
end;
W h e n y o u declare a field, y o u specify an identifier that names the fields
and their data types. W h e n y o u declare a m e t h o d , y o u specify a procedure,
function, constructor, or destructor heading. Here's the scenario in somewhat
formal form:
Field = FieldName(s): type;
M e t h o d = procedure MethodName(<parameter(s)>type);
or = function
MethodName(<parameter(s)>:type):type;
or = constructor
MethodName(<parameter(s)>:type
[;<parameter(s)>: type]); /"virtual/;
or = destructor
MethodName[(<parameters>
type)/;/virtual/;
A n object type c a n inherit the data a n d behavior (its c o m p o n e n t s ) from
another object type. T h e inheriting object is a descendant, a n d the object that
supplies the data a n d behavior for inheritance is an ancestor.
83. 2—Elements of Application Development 59
The d o m a i n o f an object type consists o f itself a n d all its descendants.
Sets
Sets define collections o f elements o f a specific scalar o r subrange type. F o r
example, the following are set types:
type
Day = (Sun, Mon, Tue, Wed, Thu, Fri, Sat);
CharSet = set of Char;
Digits = set of 0..4;
Days = set of Day;
Months = (January, February, March, April, May, June,
July, August, September, October, November, December);
T h e base type o f a set must b e an ordinal type with not m o r e than 256
possible values. Thus, the ordinal values of the u p p e r a n d lower b o u n d s of the
base type must b e in the range 0..255.
A set constructor, which denotes a set type value, is formed by writing
expressions in brackets. Each expression denotes a value o f the set.
T h e bracket notation [ ] denotes the empty set—compatible with all set
types.
For example, the following are set constructors:
[Mon..Sat]
[1, 3, I + 1 .. J - 1]
['0'..'5', 'A'..'Q', 'd'..'z', '_']
Files
A file type consists o f a linear sequence o f c o m p o n e n t s o f s o m e c o m p o n e n t
type, which can b e any type except a file type. If y o u omit the c o m p o n e n t type,
the type denotes an untyped file.
T h e predefined file type Text signifies a file containing characters orga-
nized into lines.
For example, the following are File type declarations:
type
Employee = record
ID : Integer;
FirstName: string[10];
LastName : string[20];
Address : string[40];
end;