Turbo_Pascal_Version_5p5_Object-Oriented_Programming_Guide_1989.pdf

(4828 KB) Pobierz
OBJECT-ORIENTED PROGRAMMING GUIDE
BORLAND
5AA
Turbo Pascal5,5®
Object-Oriented Programming
Guide
COPYRIGHT
©
1989. ALL RIGHTS RESERVED
BORLAND INTERNATIONAL. INC. 1800 GREEN HILLS ROAD
P ()
R()'l(
MrYY'Il
c:r()TT~
\/.411
~v
r".4 Ol'\nM..lYYll
This manual was produced with Sprint@: The Professional Word Processor
All Borland products are trademarks or registered trademarks of
Borland International, Inc. Other brand and product names are
trademarks or registered trademarks of their respective holders.
PRINTED IN THE USA.
Rl
10 9 8 7 6 5 4 3 2 1
c
o
N
T
E
N
T
s
Introduction
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
••••
0
••
0
0
0
••
About this manual
Installation ....
Special Notes
3
Online help .
4
How to contact Borland ..............
4
0
0
••
0
0
0
••
0
••
0
•••
0
••
0
0
•••••••
0
0
••
1
1
2
Chapter 1 All about OOP
0
•••••••••
0
0
•••
0
•••••••••••
0
•••
0
•••
0
0
••••••••
0
7
Objects?
8
Inheritance ......
9
Objects: records that inherit .......... 10
Instances of object types .
13
An object's fields ......
13
Good practice and bad practice
0....
13
Methods .........
14
Code and data together.
16
Defining methods ......
16
Method scope and the Self
parameter .............
17
Object data fields and method formal
parameters ...................... 19
Objects exported by units . . . . . . . . .. 19
Programming in the active voice . . ..
22
Encapsulation ....................
23
Methods: no downside ............
24
Extending objects .................
25
Inheriting static methods .......... 27
Virtual methods and polymorphism . 29
Early binding vs. late binding ...... 30
Object type compatibility .......... 31
Polymorphic objects .............. 33
Virtual methods ............. . . . .. 35
Range checking virtual method
calls ..................
37
Once virtual, always virtual ...... 37
An example of late binding ........ 38
0
••
0
0
••••••
0
••
0.0
•••••••
0
••••••
0
••••••••••
Procedure or method? ............. 39
Object extensibility ................ 46
Sta tic or virtual methods ...........
48
Dynamic objects ...................
49
Allocation and initialization with
New .............................
50
Disposing dynamic objects ......... 51
Destructors .......................
52
An example of dynamic object
allocation ........................
54
Disposing of a complex data structure
on the heap ...
Where to now?
60
Conclusion ..........
61
0
0
o •••••
0
••••
0
•••
055
0
•••
0
••
0
•••••••••••••
0
0
0
••
0
••
0
••
0
•••••••
63
Object-oriented debugging in the IDE ..
63
Stepping and tracing method calls ...
63
Objects in the Evaluate window ..... 64
Objects in the Watch window ....... 64
Expressions in the Find Procedure
command .........
64
TurboDebugger .................... 65
Stepping and tracing method calls ... 65
SCope .............
65
Evaluate Window ................. 66
Calling methods in the Evaluate
window ........................ 67
Watch window .................... 67
The Object Hierarchy window ...... 67
The object type list pane .......... 68
The local menu .................. 68
The hierarchy tree pane .......... 68
The Object Type Inspector window .. 69
The local menus ................. 69
o
••••••••••••••
Chapter
2
Object-oriented
debugging
o •••
0
••••••••••
Object Instance Inspector window .. 70
Local menus ................... 71
New error messages ................ 72
89
Overlay buffer management ..........
89
Variables ...........................
OvrTrapCount ....................
OvrLoadCount. ...................
OvrFileMode .....................
OvrReadBuf ......................
Procedures and functions .............
OvrSetRetry ......................
OvrGetRetry ......................
Overlays
in
.EXE files ................
91
91
92
92
92
94
94
95
95
Chapter 4 Overlays
Chapter 3 Turbo Pascal 5.5 language
definition
73
New reserved words . . . . . . . . . . . . . . ..
Object types .......................
Assignment compatibility ...........
Object component designators. . . . . . ..
Dynamic object type variables . . . . . . ..
Instance initialization ...............
Object type constants. . . . . . . . . . .. .. ..
@
with a method ...................
Function calls ......................
Assignment statements . . . . . . . . . . . . ..
Procedure statements ...............
Case statements ....................
With statements ............. . . . . . ..
Method declarations ................
Constructors and destructors . . . . . . . ..
Variable parameters ................
Extensions to New and Dispose ......
Compiler directive conditional
symbols ...........................
73
73
78
78
79
79
80
80
81
81
81
82
82
83
84
85
86
87
97
Internal data format of objects ......... 97
Virtual method tables ..............
98
The SizeOf standard function ......
100
The TypeOf standard function ..... 101
Virtual method calls ..............
101
Method calling conventions .......... 102
Constructors and destructors ...... 102
Assembly language methods ......... 103
Constructor error recovery .......... 106
Chapter 5 Inside Turbo Pascal
Appendix A New and modified error
messages
111
Index
113
ii
Zgłoś jeśli naruszono regulamin