:
- . .,
- . .. .
- . .. .
- . ..
- . ..
. . ..
- . ..
- . ..
- . ..
- . ..
- . ..
- . ..
.., .., ..
..
..
2001
681.3.06(075.8)
32.973-018
21
:
(. .. );
..
21
., .., ..
- : . /
. .. . - .: - . .. ,
2001. - 320 , . (. ).
ISBN 5-7038-1525-8
-
().
Borland Pascal 7.0, C++ 3.1, Delphi C++ Builder.
Wdows-poe .
,
. .. .
,
:
(( , , ,
,
. .
681.3.06(075.8)
32.973-018
ISBN 5-7038-1525-8
.. , .. , .. , 2001
. .. B^Tviana, 2001
. .. ^^, 2001
1. -
1.1.
1.2. -
1.3.
1.4.
1.5.
1.6.
1.7.
2. -
Borland Pascal 7.0
11
11
18
25
33
35
39
48
59
2.1.
59
2.2.
63
2.3.
67
2.4.
75
2.5.
83
2.6.
86
2.7. -
92
3. -
Borland C++3.1
3.1.
3.2.
3.3.
99
99
110
118
5
3.4.
3.5.
3.6.
3.7.
3.8.
3.9.
4. Windows
4.1. Windows
4.2. Windows
4.3. \V^ndows Delphi
HC++Builder
5. Delphi Pascal
5.1.
5.2.
5.3.
5.4.
5.5.
5.6. Delphi
5.7.
5.8.
6. C++ Builder
6.1. C++
6.2.
6.3. VCL-
6.4. C++, Delphi
C++Builder
129
135
138
144
154
161
169
169
175
178
192
192
202
210
219
228
233
241
251
260
260
273
283
294
306
307
310
312
.
().
( ,
,
..)
, ,
. ,
.
, .
,
,
, .
,
. ..
,
.
,
MS DOS Windows'95 ( ).
^.
.
1
. Onncaiffle ,
. :
,
,
, .
2 3
, MS DOS.
, Borland Pascal 7.0
, 1
Borland C++ 3.1.
. ,
.
, ,
2 ,
.
4
Windows'95, Windows'98 Windows NT,
5 6, ,
Delphi C++ Builder. Windows
,
Visual C++.
KOMHoneirr
,
. ,
.
. , , C++
, ,
, Pascal - ..
,
.
( , ),
.
,
,
( ), ,
. :
> ^|
^1
^|
^1
^|
^1
J,
:
:1111111
;
, ;
(
);
>
( );
- ;
-
, .
, ,
. :
|||^^^^^^^^^^^^1
||||^^
|||^^^^^^^
^^^^.
^mg^^^im^^
TMainForm
:
Form Activate
InputEditKeyPressed
NextButtonClick
ExitButtonClick
, -
.
,
. :
:
1
2 Enter
4
. ,
.
, .
1,4-6 , . . .. ;
2 - , . . .. ; 3 , . . .. .
:
(. .. )
.. (. , , )
,
.
1.
-
.
,
1.1.
,
,
.
.
.
.
,
.
,
, .
.
,
.
, (
), (. 1.1).
11
1.
'
- ^:^
^
2
. . .
. 1.1. ,
,
- . ,
.
,
,
.
(. 1.2).
.
.
, .
[3,4].
. 1.2. ,
12
1 1
,
.
:
,
,
(
);
,
(
, );
,
(
, ).
( )
( 40 ... 50 ) .
,
,
.
(, ..)
.
:
(. 1.3):
- (, ,
, ),
- (,
),
- (,
);
-
>1
. 1.3.
13
, ,
;
,
,
( 1 - 2 ).
1.1. (
). ,
.
.
,
. ,
:
.
.
.
.
.
, ,
,
:
-
.
-.
.
, .
:
^
=
=
-
-
-.
14
1.1.
,
. ,
20 ... 30 .
:
.
.
,
-
^
^
^
-
-
-
-
.
.
,
,
<> < 1> < 2>-,
- - <> -.
.
, : ,
, , .
,
:
_:
_
-
:
.
, .
15
1.
. 1.4 ,
.
, .. 12
,
.
,
.
.
, ,
,
.
PL/1, ALGOL-68, Pascal, .
,
, ,
. - ,
.
, ,
.
.
.
1 1
. 1.4.
16
7.7.
(. 1.5)
,
, ( ),
, ,
.
, (
) .
Pascal
(-+), Modula.
,
.
.
.
, ,
.
,
, 100 000 .
,
(-
). 100 000
(]^^
--
. 1.5. ,
17
1.
,
.
-
().
1.2.
-
,
,
{),
[2].
( 1.6).
.
Simula, 60- .
- Smalltalk (70- ),
, Pascal, C++,
, Modula.
-
, ,
.
,
() .
,
, , , ,
, .
,
,
.
-
.
:
,
, , , , ,
.
, .
18
1.2.
2
(^^
S
<^1^
-TV
--
. 1.6.
-
. -
, ,
,
.
: ,
, - , , -
..
(
19
1.
, )
().
-
,
.
:
-
( );
-
(
).
:
,
;
,
.
(
)
.
- ,
().
,
.
,
.
- .
.
.
/ - ,
, ,
, .
( - ,
-
).
/ - ,
, , , - .
,
, ,
.
20
1.2.
-
/. -
,
(
).
- ,
(
).
(, ,
. .) ,
.
, .
.
, C++
, .
:
,
(
);
;
.
(
- ) (
-
).
- ,
{ ),
.
-
, .. .
,
. ,
,
.
,
.
.
(- )
21
7.
(
MS DOS), ( Windows).
-
, , /
, ,
.
:
,
, ;
, ,
;
, ;
,
.
- .
- .
-,
.
.
, . ,
, , -
, C++ - -.
,
, -
- ,
, , Borland Pascal ( 5.5), C++,
Delphi ..
. 1.1
.
Borland
Pascal 7.0.
,
.
.
.
Delphi C++Builder.
MS DOS
, .
Windows. e n d o w s
22
7.2.
,
.
1.1.
Borland 1
Pascal 7.0
1
:
()
()
()
()
1 :
-
~
C++Builder
1 :
Borland
DelpM
C++3.1
Windows
Windows
onpej
23
1.
.
: , , , .
.
. - .
,
( ).
,
, ,
.
. :
,
(
);
,
.
:
, .
(,
, , ..).
, , .
, (
), ,
/ (,
, ),
..
.
.
.
, , , ,
. .
, ,
(
).
, ,
, .
, ,
.
, , .
24
1.3.
.
.
. ,
,
,
, .
- ,
, .
.
,
,
.
,
, , ,
. ,
, .
, -
.
.
1.3.
,
, ,
.
,
( ) ,
(,
, ,
).
.
, .
,
, (..
,
), .
25
/.
, ,
.
,
,
,
.
.
1.2. (
).
,
( ).
.
, .
,
,
.
(. 1.7).
tl, t2, t3, ... - ,
; 1 - 3 - .
(
10
3
2
^^^^^^^^^^^!.
tl
t2
t3 t4 t5
6 t7 t8
t9
tlO
. 1.7.
26
1.3.
) ( ).
.
, , - .
, .
- , ,
. , ,
, ,
, .
.
.
,
.
,
.
,
. ,
.
, :
.
,
,
.
,
, . ,
, ,
.
,
.
,
. ,
.
, ,
1.
.
. 1.8
. ,
.
27
1.
^i
?
^
?
>>
>.^ ?
V
J
<
1
. 1.8.
. ,
1 , -
, .
.
, ,
, . ,
, ,
.
,
.
,
. .
1.3. ( ).
,
. , ,
. ,
- ,
-
.
.
.
(. 1.9).
28
1.3.
^ ?
>^
^
. 1.9. :
1 - ? 3 - ?
2 - ; 4 -
,
.
.
.
, ,
,
,
,
.
, . ,
.
, .
1.4. .
,
: .
,
.
.
,
,
/ .
29
I.
^<
. 1.10.
-
, .
,
.
, : ( ,
) -
(. 1.10), .
: ,
, , .
.
,
.
.
, , , ,
.
1.5. (
).
,
(. 1.1).
,
. ,
,
.
, ,
(. 1.11).
, : ,
, . .
.
-
,
, , 30
1.3.
. 1.11.
( )
(. 1.12).
, . ,
,
. ()
.
, ,
- ,
. ,
- ,
. ,
- ,
- .
. 1.12.
31
1.
, .
.
.
(, , )
.
( ,
) .
.
. 1.13 (
, . 1.3).
,
:
1.
: - ,
- .
2.
:
( , ,
- ..);
, ( ,
, , ..).
>1 .
'
'^
. 1.13.
32
1.4.
3. ,
, ..
.
1.4.
,
.
, , ,
.
, ,
,
. , 1.5
, ,
,
,
.
:
, ,
, , ,
.
, ,
( 1.3) :
, , -
.
, ,
.
.
,
, ..
.
, ,
.
,
, (, ).
, ,
.
.
, , ,
.
^-.
33
1.
. ,
.
.
-^*,
, ,
.
, (
) .
, ,
, ,
, .
, .
(. 1.14):
;
;
- ;
- ;
-
(
).
, , ,
.
, ,
( )
, -
-
:
.
J
^
^
^
\
^
iD
,
.
^ 1 X I
1. ,
XI
, ,
1
^|
(. 1.15), ,
1
,
. 1.14.
, ,
- .
/ ^
34
1.5.
.
2
. 1.15.
,
( ,
), (
) ( - ,
, ).
2.
, ,
- ( /).
.
1.5.
, ,
, .
,
.
.
- .
- ,
, , .
.
.
, (. 1.16).
.
.
35
>
> ^
>
\
. 1.16. -
-
1.6. ( ).
,
(. 1.17).
: XI, Y1, 2, Y2 -
Color - .
,
(1,1)
, -
. ,
,
.
,
(2,2)
, .
. 1.17.
,
.
, :
:
X1,Y1,X2,Y2, Color
( 1 ,aY 1 ,2,2,1)
.
,
,
, .
36
7.5.
,
. , ,
.
.
. ,
11 , (
):
< >.< >
< ,
>
< ,
>
.
,
, ,
.
( )
.
, ,
. ,
, .
37
1.
'
. 1.18.
(. 1.18).
,
() ().
.
, - :
.
.
, -
. , ,
.
.
1.7. ( 1.5).
(. . 1.13).
: , , .
. ,
.
, :
.
,
. ,
.
-.
.
, ,
,
.
38
1.5.
.
, .
, _,
.
, .
, .
,
>1 ,
.
(
) ,
.
. .
:
:
;
( );
(, );
();
_;
;
_;
;
.
.
.
,
.
.
1.6.
, ,
,
, .
39
1.
.
( ).
, ,
, - .
-
.
,
, - .
( )
(. 1.19).
, .
1.8. ( ).
-,
.
_:
__ - : :
_(1);
.
__
. __
_ (. 1.20).
, , , C++,
. ,
, ,
, .
, C++ ,
( - 3.3).
-
- 1
- 2
. 1.19.
40
1.6.
: (aColor)
. 1.20,
,
,
.
.
, ,
.
.
, , ,
.
,
. , ,
- .
,
.
.
,
(),
.
.
,
:
- ,
- ;
, , LISP SMALLTALK;
{ ) - ,
-
; ,
( , , ..);
41
7.
, ', , C-+-I-
;
( ) -
,
( ),
;
( ) -
-
, ( ),
( );
-
(, C++),
( ).
1.9. ( __).
.
- Xt, Yt , - Text.
, ,
.
(!), . ,
.
- __
(. 1.21).
,
.
__ - : :
Xt, Yt, Text
(aXl,aYl,aX2,aY2,aColor,aXt, aYt, aText)
.
.
, ,
.
.
,
, .
:
42
1.6.
:
:
:
:
. 1.21.
-
,
- ( - -
, - self this);
, -
-.
. , :
( - 2.3, 3.4).
. ,
.
, , ,
, ,
.
.
.
1.10. .
Out Print, . Out,
Print. Out
: Out,
1
Print; virtual
-,
- (. 1.22).
: Print; virtual
Out
2
- ,
Print
. 1.22.
, (. 1.23).
1.10
43
1.
-
Out
/ " ^ " ^ ^
Print
>1
-^
>fc
Out
./^~^^^^^^
Print
. 1.23.
, :
Out, . ,
Print .
Print
, ,
- Out Print -.
Print ,
, , Print
.
, Out,
Print .
, ,
.
virtual.
, , -,
. , ,
. ,
, .
,
(). ,
.
(. 1.24).
.
, .
, -:
- -, ,
-, (. 1.25).
.
44
1.6.
. 1.24.
. 1.3 ,
,
(. . 1.15).
:
.
,
, . .
,
- ,
.
,
. ,
, .
.
-
-
. 1.25. ,
45
1.
1.11. (
- 1.5).
,
(. 1.26).
__.
. 1.26.
. .
. ,
.
- : __:
:
( 1 ,aY 1 ,aX2,aY2,aColor,aXt,aYt,aText,
bX 1 ,bY 1 ,bX2,bY2,bColor,bXt,bYt,bText)
.
1
.
, (. 1.27).
: -
, - -.
XI
Y1
[ZZI
Y2
Color
Xt
Yt
Text
IZZ]
[ZZ]
]ZZ]
IZZ]
\ 1
XI
CZ]
Yl
[ZH
X2
ZZ]
Y2
ZZ
Color Z Z
Xt
ZZ
Yt
ZZ]
Text
ZZ
. 1.27.
46
, , :
< >.< >.<
>
1.6.
. ,
(1 ) ,
,
( ) .
1.12. ( ).
,
(
- ). :
1. -
(. 1.28),
.
2. -
.
.
, ,
:
:
-:
- :
()
.
-:
:
- : ;
();
;
.
2,5*xV(x-3)/(x+4)
. 1.28.
47
1.
,
.
1.7.
. .
,
, , ,
, .
.
.
. - , ,
.
(. 1.29).
, : , , ..
, RTTI (Run Time Type
Information - ).
:
;
-
, ,
;
,
( ) -
. 1.29.
48
1.7.
,
.
. -
.
, .
, &&
, : .
,
.
, . ,
,
.
(. 1.30).
.
.
.
:
1)
-
;
.
C++
, ,
.
2)
3
1
'"7
^^-""^
^^-''
2
-^
^
. 1.30.
49
1.
( )
.
,
.
1.13. ( ). 1.3
,
,
.
: , (. . 1.10).
,
.
- (. 1.31).
1.
.
1:
X, Y, R, Color
__
^^
1
J
1
. 1.31.
50
1.7.
2. :
, .
! :
X, , . Color
__
(, , , aColor,
__)
(aColor)
_ (aR)
_ (, aY)
__ (^)
.
,
.
,
, :
_:
3.
X, Y, R, Color
__
_
_
1.
_ (aR)
_ (, aY)
__ (_)
.
aFigura_type ,
.
,
,
.
. -
, .
. ,
, ,
. , ,
( , ..).
- ,
, .
,
(. 1.32).
,
. ,
(, , ).
-.
, (,
- , ).
, ,
, - -.
. - -
, - ,
.
. 1.32.
52
1.7.
:
< >:=< >
- < >
< >
< >:=< >
-.
: ,
(
); , , ,
.
( -).
1.14. ( ).
,
.
:
__
.
, :
_, ,
,
, , ,
.
()
_
_
_
.
:
:= _
-
,
53
1.
:=
-
. , ,
, .
.
>1
, ,
.
.
1.15.
( ).
:
, __
__()
__(_)
.
, ,
,
, :
_ ()
.
. ( )
,
. ,
, , ,
.
:
( - ) C++.
! C++.
,
,
54
1.7.
. , ,
,
.
1.16. ( ),
, ,
, (
_):
(_)
: _
__: _
__
(: _)
_: _
_: _
_;: _
.
, :
(1)
(!)
, ,
.
.
,
(, , ..).
.
, ,
.
.
, ,
55
1.
,
,
(, [ ),
( ,
).
. ,
:
- .
,
. , ( )
( ) , ( ) ,
:
(. 1.33).
, ,
,
, , .
, .
.
, .
, ,
, .
,
, , .
,
,
. .
|:;||||||||||||
. 1.33.
56
1.7.
.
-
.
(try...except - Delphi Pascal, try... catch - -+, try ...
ex
cept - ). ,
.
- ,
.
(try... finally - Delphi Pascal, try... finally -
, try... finally - C++Builder).
,
: ,
.
, ..
(raise - Delphi Pascal, throw
- ++, RaiseException - ).
,
.
, -
.
, , ,
..
,
.
:
,
-
;
, , ;
,
, .
.
,
()
.
57
1.
,
() ,
.
1. .
? .
2. , .
3. ?
?
4. . ?
5. , ?
,
? ,
.
6. . ?
.
7. ?
?
8.
.
2.
-
BORLAND
PASCAL 7.0
Borland Pascal 7.0 ,
.
noddepjtcKu
( , . .).
.
2.1.
, - ,
, ,
.
Borland Pascal 7.0 .
, : ,
() :
: {byte,
shortint, word, integer, longint, real, single, double, extended, comp);
{boolean); {char); {string); (pointer);
; ; ; {text, file, file of..,); ;
.
Borland Pascal 7.0.
(
, , ).
,
,
.
Procedure < >.< >;
< , >
Begin <>
End;
2.1.
:
-
:
< >.< > := <>
- ,
(
Init);
- :
Const < > : < > =
(< 1> : < 1>;
< 2> : < 2>;
< >:< >);
.
2.1. ( ).
, .
,
Crt: Window, Textbackground Clrscr.
,
. :
Program WinOb;
Uses Crt;
Type
{ }
Win = Object { }
{ }
XI, Y1, { }
2, Y2, { }
Cf: byte; { }
{ }
Procedure InitfXnl, Ynl,Xn2, Yn2,Cfn:byte); { }
Procedure MakeWin;
{ }
Function GetSizeX: byte; { X}
Function GetSizeY: byte; { Y}
End;
{ }
Procedure Win.Init;
Begin 1:=1; Yl:=Ynl; 2:=2; Y2:=Yn2; Cf:=Cfii; End;
Procedure Win.MakeWin;
61
Begin Window{XlJlX2J2)\
Textbackground{Cf)\ Clrscr End;
Function Win.GetSizeX;
Begin GetSizeX: =X2'X1+1 End;
Function Win.GetSizeV;
Begin GetSizeY:=Y2'Yl^l End;
Var Winvar: Win; { }
Begin
with Winvar do { Winvar }
begin
Init(l, 1,80,25,1); { }
Make Win;
{ }
Writeln(Cf,' - ,GetSizeX,' - \GetSizeY); { }
end;
Readkey;
End
,
: (1 - 80 25).
with.
:
WinvarJnit{l, 1,80,2 5,1);
Winvar. Make Win;
Writeln(Winvar.Cf,' - ' , Winvar.GetSizeX,' - ', Winvar.GetSizeY);
Self. Self
,
. ,
. , -
,
. ,
Self.
Rec - Record
{ }
X, Y: word;
{ }
end;
Pas ^Object
{ }
Xj : word;
{ }
Procedure Init(P: Rec); { }
end;
Procedure Pos.Init;
Begin
62
2.2.
with do { }
begin
{ }
Self.X: = X;
SelfY:=Y;
end
End;
Var R:Rec; P:Pos;
Begin R.X: =1; R. Y: =2;
{ }
Plnit(R);
{ }
Write{ ,' - \. Y); { }
End.
2.2.
1 : ,
( ).
Borland Pascal 7.0 ,
, .
.
.
-
. ,
-.
, -,
.
.
1. .
2. ,
.
3. , -.
.
4. - ,
- , .
,
44 {Field identifier expected-
).
. ,
.
63
-:
< ->=]1(< ->)
< ->
< ->
End;
2.2 2.3 .
2.2.
( ). (Symb),
.
Program SymbOb;
Uses Crt;
Type
Symb = Object { }
{ }
XI, Yl, { }
2, Y2, { }
CfCs, { }
Col,Lme:byte; { }
Sym.'char;
{}
{ }
Procedure Init(Xnl, Ynl,Xn2, Yn2,CJh,Csn,Cl,Ln:byte;Sm:Char);
Procedure Make Win; { }
Procedure Print; { }
End;
Procedure Symb.Init;
Begin
Xl:=Xnl;Yl:=Ynl;
X2:=Xn2; Y2:=Yn2; Cf:=Cfii;
Cs:=Csn; Col:=Cl; Line:=Ln; Sym:=Sm;
End;
Procedure Symb.MakeWin;
Begin
Window(XlJl,X2,Y2); Textbackground(Cfi; Clrscr
End;
Procedure Symb.Print;
Begin
TextColor(Cs); Gotoxy(ColLine); Write(Sym)
End;
Var Symbvar: Symb; { }
Begin
Symbvarlnit(], 1,80,25J, 1,40,12, 'A'); {}
64
2.2.
Symbvar.MakeWin; { }
Symbvar.Print;
{ }
Readkey;
End
2.1 2.2, , XI, Y1,
2, Y2, Cf Win . , Symb
Win.
. , ,
.
2.3. ( ).
. 2.1 ,
, .
, -
, .
, Win
, Symb - .
2.3 Symb
Win.
Program WinSymbOb;
Uses Crt;
{
}
{ Win 2.1 }
{
}
: XI, Y1, 2, Y2 -
Cf ~
: Init, Win, GetSizeX, GetSizeY
: Cs -
Col, Line -
Symb
Sym -
: Init, Print
. 2.1. 2.3
65
{ }
Procedure Init{Xnl YnlXn2, Yn2, Cfn, Csn, CI, Ln: byte;Sm: Char);
( }
Procedure Print; { }
End;
Procedure Symb.Init;
Begin
Win.Init(Xnl, Yn],Xn2, Yn2,CJn); { }
Cs: =Csn; Col: =Cl; Line: =Ln; Sym: =Sm;
End;
Procedure Symb.Print;
Begin TextColor(Cs); Gotoxy(Col,Line); Write(Sym) End;
Var Symbvar: Symb; { }
Begin
with Symbvar do begin
Init(l, 7,80,25,7,1,40,12, 'A'); { }
Make Win;
{ }
Print
{ }
end;
Readkey;
End
2.2.
,
Symb. ,
GetSizeX GetSizeY Win, Win.
.
. ,
.
,
.
: .
, , -
, -
.
:
< -> := < ->
2.3
Win Symb, :
66
2.3.
{
Var
Winvar: Win;
{-}
Symbvar: Symb; {-}
Begin SymbvaKlnit(lJM25J,l40J2,
'A');.
Winvar: = Symbvar; { }
Winvar.MakeWin; { }
Write(Winvar.CJ); { 7}
End.
,
,
{
Var
Winvar: ^Win;
{ -}
Symbvar: ^Symb;
{ -}
Begin New(Symbvar);
{ }
Symbvar^.Init(lJ,80,25JJ,40J2, '');, {}
Winvar: = Symbvar; { }
Winvar^ : = Symbvar^; { }
Winvar^,MakeWin; { }
Write (Winvar^. Cf);
{ }
Dispose (Symvar);
{ }
End.
2.4.
2.3.
Borland Pascal .
.
.
.
,
.
.
67
{
).
Borland
Pascal 7.0.
2.4. .
, ,
.
\Wn Symb: Lot
Symb. Print, Symb
(. 2.2). Lot ,
, N .
Program WinSymbLot;
Uses Crt;
}
2.3.
, ,
.
vir
tual:
Procedure < >(< >); virtual;
Function < > (< >):< >; virtual;
.
1. ,
, ,
. .
2. ,
.
3. , , 1 - . Procedure
Constructor.
( - 1.6).
,
. ,
, , Init.
,
. ,
.
.
:
1)
;
2)
,
( ).,
-;
3) ,
,
.
.
,
.
70
2.3.
,
2.4.
2.5. .
Win - Symb - Lot ,
, Win
Run, .
Win
Print. Win -
( ). Print Symb Lot
( ). Win Print ,
(,
) Print.
Run Symb Lot.
, Run,
, Print
, , ,
Print ( 1 ).
.
Init.
Program Met Virt;
Uses Crt;
Type
Win = Object { }
XlJlX2J2,Cf:byte;
Constructor Init(Xnl Yn],Xn2, Yn2, Cfn:byte);
Procedure MakeWin;
{ }
Function GetSizeX: byte; { X}
Function GetSizeY: byte; { Y}
Procedure Run;
{ }
Procedure Print; virtual; { }
End;
Constructor WinJnit;
Begin Xl:=Xnl; Yl:=Ynl; X2:=Xn2; Y2:=Yn2; Cf:=Cfii; End;
Procedure Win.MakeWin;
Begin
Window(XlJlX2J2);Textbackground(Cfi;ClrscrEnd;
Function Win. GetSizeX; Begin GetSizeX: =X2'X1+1 End;
Function Win.GetSizeY; Begin GetSizeY: =Y2-Y1+1 End;
Procedure Win. Run;
Begin MakeWin; { }
Print
{ }
End;
71
2.3.
,
MakeWm Print, - ^\^ .
Print
(VI,V2 V3).
virtual Print,
Print (
).
Program ;
Uses crt;
Type
Win = Object { }
Xl,YlX2J2,Cf:byte;
Constructor Init(Xnl, Ynl,Xn2, Yn2, CJh:byte);
Procedure MakeWin;
{ }
Function GetSizeX: byte; { X}
Function GetSizeY: byte; { Y}
Procedure Print; virtual; { }
End;
Constructor WinJnit;
Begin XI:=Xnl; Yl:=YnI; X2:=Xn2; Y2-Yn2; Cf:=CJh; End;
Procedure Win.MakeWin;
Begin Window(XlJlX2J2);
Textbackground(CJ); Clrscr End;
Function Win.GetSizeX; Begin GetSizeX: =X2'Xm End;
Function Win.GetSizeY; Begin GetSizeY:=Y2'Y1-^1 End;
Procedure Win. Print; Begin End;
}
{
{
}
}
Win - Symb - Lot ( 3
). -
-,
:
{
{
Win
}
{
Symb Lot 2.5
}
W=^Win; { }
Var V:W; V2:Symb; V3:Lot;
Procedure PolOb(VarObj:W); Begin Obj\MakeWin; Obj\Print End;
Begin
New(V); V14nit(20,5,40J5,5);
V2.Init(10,3M20,3J,30J0, 'A');
V3.Init(l,lM25,5,3,40,12/B\]0);
PolOb(Vl); Readkey;
V1:=@V2; { 1- }
PolOb(Vl); {: A} Readkey;
V1:=@V3; { 2- }
PolOb(Vl); {: } Readkey;
End
lypeOf:
(< >): Pointer ;
2.4.
.
{5/?+}.
.
, ^ {$R+) .
Borland Pascal
( 2.1).
, 2.5
:
Const
Vl:Win=(Xl:20;Yl:5;X2:40;Y2:15:Cf:12);
V2:Symb=(Xl:10;Yl:3;X2:60;Y2:20;Cf:3;
Cs:l;Col:30;Line:10;Sym: 'A');
V3:Lot=(Xl:l;Yl:l;X2:80;Y2:25;Cf:5;
Cs:l;Col:40;Line:12;Sym: 'B \'N:10);
, ,
.
2.4.
, ,
, ,
.
, :
Var < > ; ^< >;
New:
2.4.
,
Borland Pascal:
Function HeapFunc(size: Word) .integer; far;
Begin HeapFunc:=l; end;
HeapError: =@HeapFunc;
New
nil, .
, ,
.
Fail . Fail
.
nil .
2.7 ,
.
2.7.
. WinD,
,
( ), .
6 , 1 - 4 , 5 6 -
.
Program DinObj;
Uses Crt;
Type
APtr = ^Vaw; { }
Vow = array [7.. ] of byte;
WinPtr = ^WinD; { }
WinD = Object
A:APtr;
{ }
Constructor Init(An: Vow); {}
Destructor Done; virtual; {}
Procedure Make Win;
{ }
Procedure ColorWin;
{ }
End;
Constructor WinD.Init;
Begin
77
New(A); { }
ifA-nil then { }
begin WinD.Done; Fail end;
^:=; { }
End;
Destructor WinD.Done;
Begin ifAonil then Dispose (A); { A} End;
Procedure WinD.MakeWin; { }
Begin mndow(A''flJA^f2J,A''f3J,A^f4J)
End;
Procedure WinD.ColorWin;
Begin TextbackGround(A''[5]); TextColor(A''f6J); Clrscr End;
Function HeapFunc(size:Word):integer; far; Begin HeapFunc:=l; end;
Var V: WinPtr; { }
Const
Am: Vaw=(l, 1,80,25,4,1); {
, }
Begin
HeapError: =@HeapFunc; { }
Clrscr;
New(VfInit(Am));
{ }
if V-nil then Halt(2); { , }
V^.MakeWin;
{ }
V\ColorWin;
Dispose(V,Done); { }
Readkey;
End
.
false, fail.
2.8.
.
Program DinObj;
{
{
WinD
}
{
2.7
}
Var W :WinD; { }
Const
: Vaw=(l, 1,80,25,4,1); {
, }
78
2.4.
Begin
HeapError: -@HeapFunc; { }
Clrscr;
if not WJnit(A) then Halt(2); { , }
W.MakeWin;
{ }
W.ColorWin;
W.Done; { , }
Readkey;
End.
,
.
2.9. (
). , ,
(
).
,
: ,
, 1, (. 2.3).
:
- - ,
(. 2.4).
#f*
'^F
'#
^'
v ^
. 2.3. :
- ; b -
79
(^ 1 . .^ N ^ ( N-f 1^... (^ j
. 2.4.
.
, MS DOS,
, .
(. 2.5). Snow ,
. ,
Snowl Snow2 - .
-
.
.
Init.
Drag.
Drag Snowl,
Snow2.
- , ..
Drag ,
. , Drag
(3- - 2.3).
,
: V -
: Init -
Done -
Create -
Drag -
( )
: Vh -
: Drag -
: Drag -
. 2.5.
80
2.4.
.
, Drag
().
Program SnowOb;
Uses graph, dos, crt;
Type
Ptr = ^Vt; { }
Vt = array [L.6] of integer; { }
Snow = Object
{ }
V: Ptr;
{ }
Constructor Init;
{}
Destructor Done; virtual; {}
Procedure Create; { }
Procedure Drag;virtual; { }
End;
Constructor Snow.Init; Var c, i.word;
Begin
New(V);
{ }
V^[4]: -Random(14)-^l; { }
V^[5]:=Random(30)+2(y; { ( )}
V^[6]: =7;
{ - }
Gettime(i, i, i, );
{ }
for i: =0 to do
begin
{ }
V''[l]:=Random(GetmaxX); V''[2]:=Random(GetmaxY);
V^f3J: =Random(20) + J;
end;
End;
Destructor Snow.Done; { V}
Begin if V< >nil then Dispose(V) End;
Procedure Snow.Create;
Var : real;
Begin
u-0; Setcolor(V'^f4J);
repeat { 12 }
LinefV'flJ, V^[2],Round(V'^[l]^V''[3]''cos(u)),
Round(V'^[2]-^V''[3J*sin(u)));
: =u+pi/6;
untilu>2*pi;
End;
Procedure Snow.Drag;
Begin End;
81
Snow] = Object(Snow) { }
Vh'.byte; { }
Constructor Init(Vhn:Byte);
Procedure Drag; virtual; { }
End;
Constructor Snow Unit; Begin Snow.Init; Vh: = Vhn End;
Procedure SnowLDrag;
Varcbyte;
Begin
c:= V^[4]; V^[4J:=0; { }
Create ;
{ - }
V^f4J: =;
{ }
ifCV'fSJ < ^^[5]) and (^^[2]+ V'fSJ < GetmaxY) then {
}
begin inc(V^[3], Vh); Create { } ^rf
else V^[6]: =0;
{ }
End;
Snow2 = Object(Snowl)
{ }
Procedure Drag; virtual; { }
End;
Procedure Snow2.Drag;
Var : byte;
Begin
c: = V^[4]; V^[4]: =0; {1 }
Create ; { }
V^[4]:=c; { }
if V^[2]+ V^[5] < GetmaxY then {
}
begin inc(V^[2], Vh); { } Create end
else V^[6]: =0; { }
End;
Sdl =^Snowl; { }
Sd2 =^Snow2; { }
Const N=100; { }
Var S: array[0..N] of^Snow; { }
,, /, , : integer; {>1 }
Begin
a:=Detect; Initgraph(a,r, 'D:\BP\BGr);randomize;
Setbkcolor(Black); { }
: =40; { }
for i:=0 to do { }
82
2.5.
begin : -random(2); { }
ifm^l then S[i]:=New(SdlMt(l)) else SfiJ:=New(Sd2Mt(l));
S[i]\Create;
end;
repeat { }
for i: =0 to do
begin SfiJ^.Drag; { }
ifSfiJ^. V^[6]=0 then { }
begin
Dispose(S[iJ,Done); { }
ifrandom(2)^0then
SfiJ:=New(Sdl,Init(l))
else S[i]:=New(Sd2,Init(l)); { }
S[i]^. Create;
{ }
end;
end;
until Keypressed;
for i: =1 to do { }
Dispose(SfiJ,Done);
End.
2.5.
.
, .
,
. ,
, .
, ,
, .
(.tpu)
, ,
. ,
, .
,
. ,
,
.
private
.
, .
, private,
.
83
, ,
.
,
public.
Unit.
- :
Unit < >;
Interface { }
2.5.
WinD = Object
private { } A:APtr; { }
public { }
Constructor Init(An: Vow); {}
Destructor Done; Virtual; {}
Procedure MakeWin;
{ }
private { }
Procedure ColorWin; { }
End;
Implementation { }
Constructor WinD.Init;
Begin New(A); ifA=nil then begin WinD.Done; Fail end;
A^:=An;
End;
Destructor WinD.Done;
Begin if Aonil then Dispose (A); End;
Procedure WinD.MakeWin;
Begin Window(A''f]JJ^f2JJ''[3JJ^f4J);
SelfColorWin End;
Procedure WinD.ColorJVin;
Begin TextbackGround(A''[5J); TextColor(A''[6]); Clrscr End;
End.
, ObjUnit:
Program ModOb;
Uses ObjUnit;
{ }
Var
V: WinPtr; { }
: Vow;
{ }
Begin
[1]:=1; [2]:=1; Af3J:=80; Af4J:=25; { }
A[5J:=7; A[6J: -1;
{ }
New(V,Init(A));
{ }
ifV^nilthenHalt(2);
V\MakeWin; { }
Dispose(V,Done) { }
End
, :
^[1]:=1; ^[2]:=1; ]:=60;
'^[4]:=20; ^[5]:=3; ^[1]:=2;
85
2.6.
Ob_Field: OutS; { }
Procedure Init(Xnl, Ynl,Xn2, Yn2,Cfii: byte; Obn: OutS);
Procedure Make Win; { }
End;
Procedure Win.Init;
Begin Xl:=Xnl;Yl:=Ynl;
X2:=Xn2; Y2:=Yn2; Cf:=Cfh;
Ob_Field:=Obn; { }
End;
Procedure Win.MakeWin;
Begin
Window(XlJlX2J2);
Textbackground(Cfi; Clrscr;
ObFieldPrint; { Print OutS
Win}
End;
Var V:Win; FrOutS; { }
Begin
KInit{ ' \1); { }
V.Init(20J0,35, );
{ - -}
V. Win; { }
Readkey;
End.
,
, .
2.12. - .
,
(),
(. 2.6).
.
, .
.2.7.
: Zona () Cir
(). Zona ,
, N - -
Cir.
Init, Out Run.
Control,
-
(.2.8).
Cir . ,
, ,
87
. 2.6.
.
.
,
.
.
Cir Zona. Z
Cir.
Control Z
.
- ,
Control .
j -
0
f
i\
^
>
^
[ 1 J [ :( 2 1 ...
' * % ^ ,
f
. 2.7.
1 ; 2
88
2.6.
Cir
: X, Y -
R, -
: Init -
Out -
Move -
Zona
: X, Y -
Lx, Ly -
- 4^ir
N -
: Init -
Out -
Run -
Control -
. 2.8.
, Zona.
Program MoveCir;
Uses graph, crt;
Type
Cp=^Cir;
{ }
Cir=Object
{ }
X, Y,R, ,
{ , }
Dx,Dy: integer; { }
Constructor Init(Xn,Yn,Rn,Cn,Dxn,Dyn:integer); {}
Procedure Out; { }
Procedure Move; { }
End;
Constructor Cir.Init;
Begin R: =Rn; =Cn; Dx: =Dxn; Dy: =Dyn; X: =Xn; Y:=Yn End;
Procedure Cir Out;
Begin Setcolor(C); Circle(X,Y,R) End;
Procedure Cir. Move;
Var cc: integer;
Begin
cc: =C; C: =Getbkcolor; Out; C: =cc; X: =X+Dx; Y:=Y+Dy; Out;
End;
Type
mascp=array [1..100] ofCp; { }
Zona=Object
{ }
X, Y,Lx,Ly,
{ }
C'word;
{ }
P:mascp;
{- }
N:byte;
{ }
89
2.6.
V.mascp; { }
a,rg,k,dj, { }
x,yJxJyJmHcz, { }
., {max }
,,, { }
,, { }
dx,cfy:integer; { 1 }
Begin
Clrscr; WritelnC: \20);
Write{ ' - '); readln(x);
Write{ ' noY- '); readln(y);
Write{ ' - '); readln(lx):
Write{ ' Y- '); readln(ly);
cz:=random(14)-^l; { }
iflx< =ly then Imin: =lx else Imin: =ly;
rm:=random(round(lmin/2))-^3; {max }
nmax:=sqr(round(lmin/(2*rm+l))); ifnmax>100 then nmax:=100;
Write{'ouecmo ( ',nmax,') - '); readln(n);
Write{'3adepDiCKy- '); readln(d);
xc: ^x-^rm-^l; yc: -y+rm+1; k: =n;
while k>0 do
begin { }
: -random(rm)+7; : =random(15)+1;
repeat dx:=random(5)'3 until dx<>0;
repeat dy:=random(5)-3 until dyoO;
if(xc+rm+l) < (x+lx) then
begin New(VfkJ); VfkJ^Jnit(xc,yc,r,cCfdx,dy); {}
dec(k); xc:=xc-^2*rm-^I
end
else if(yc+rm+l)< (y+ly) then
beginyc:=yc+2*rm+l; xc:=x+rm+l end;
end;
a:=Detect; Initgraph(a,rg, ':\\);
ZJnit(x,y,lx,ly,cz, V,n);
{ }
Z Out;
{ }
repeat
Z.Run;
{ }
for i:=l to 10 do delay(d);
until Keypressed;
Closegraph;
End
91
1.1.
-
.
2.13. . . ,
(. 2.9).
.
.
.
( ).
.
"^ X
B
y
t*
"
. 2.9.
92
2.7.
{ j
1J 2J . . .
(^ 1^ (2)
[ MJ
. . . (^!^
. 2.10. :
1 - ; 2 -
, ,
, (. 2.10).
.
.
:
- -
;
- - .
,
, .
1. ,
?
2. , ,
?
3. , ,
?
4. ? , ?
, ,
?
, , ,
, .
:
,
Init
Outs.
Move Tie, Tie Move
, (
- ).
93
Cchar
:
Ch -
-
X, Y -
Lx, Ly -
:
Init -
Print -
Line
: -
L -
D -
: Init -
Outs -
Tie -
Move -
LinMovX
: Tie, Move
LinMovY
: Tie, Move
: Re -
Xc, Yc -
V -
: Tie, Move
. 2.11.
LinMovCir
: LinMovX - , LinMovY -
LinMovCir - .
,
Move Tie (.2.11).
Line -
Cchar. ,
Cchar ,
Line , ,
, Line. Print
. ,
: , ,
.
:
,
.
( private).
, .. ,
, .
:
UnitEx_2_13a;
Interface
Type
Pc=''Cchar;
94
2.7.
Cchar = Object
{ }
private
Ch:char;
{ - }
,
LXyLy:integer; {,, }
public
Constructor Init(Chn: char; Cn,Xn, Yn: integer);
Procedure Print;virtual; { }
End;
Type
Line=object
{ }
private
' [L.lOO] of Pc;
L'byte; { - }
D:real; { - }
public
Constructor Init(S: string; ,, Yn: integer; Dn: real);
Procedure OutS; { }
private
Procedure Tie(i:byte;varX,Y:integer); virtual; { }
Procedure Move(i:byte);virtual; {}
End;
LinMovX=object(Line)
private
Procedure Tie(i:byte;varX.Yinteger); virtual;
Procedure Move(i:byte);virtual;
End;
LinMovY=object(Line)
private
Procedure Tie(i:byte;varX,Y:integer); virtual;
Procedure Move(i:byte);virtual;
End;
LinMovCir=object(Line)
private
Re,
Xc, Yc:integer; {, }
V: array [L.lOO] of real; { }
public
Constructor lnit(S: string; ., Ycn:integer;Dn:reaI);
private
Procedure Tie(i:byte;varX,Y:integer); virtual;
Procedure Move(i:byte);virtual;
End;
95
Implementation
|:|:||||9|9|:|:|:| ^ ^ ^ * * * * * * * * * * * * * J
Procedure LinMovYTie;
BeginX:=M[i]\X+M[i]\Lx;
Y:=M[i]\Y'M[i]\Ly
end;
Procedure LinMovYMove;
Begin
M[i]\ Y: ^Round(M[i]\ Y+D);
if(D>0) and (M[i]\ Y>Getmaxy'M[i]\Ly) then M[i]\ Y: =0;
96
2.7.
Sc2.Init{' ',
14,GetmaxXdiv 2,GetmaxYdiv 2,-0.05);
repeat
{ }
Sxl.OutS; Sx2.0utS; Syl.OutS;
Sy2.0utS; Scl.OutS; Sc2.0utS;
Delay{d);
until Keypressed;
Closegraph;
End
1. Borland Pascal 7.0? .
?
2. ? .
Self? ?
3. .
Borland Pascal 7.0 ?
.
4. Borland Pascal 7.0? ,
. ,
.
5. ?
?
6. ?
7. .
.
3.
-
BORLAND C++ 3.1
C++, Borland C++ 3.1,
Borland Paskal 7.0.
,
, ( , ),
3.1.
+-, , -
,
, .
:
class < >
{ private:
< () >;
protected: < >;
public:
< () >;
};
,
, ,
.
-
.
, private,
.
, / ( 3.5) .
, protected,
.
, . ~
.
99
, &1 public, .
.
.
.
, private.
. ,
,
.
, ,
::.
, :
< > < >:: < >(< >)
{< >}
C++,
, (inline).
,
, , .
, ,
:
Uinclude <stdio.h>
Uinclude <conio,h>
class X
{private:
char c;
public:
int x,y;
/*
*/
void print(void)
{ clrscrQ;
gotoxy(x,y); print/ %c", );
x=x+10; y^y-^S;
gotoxy{x,y); print/ %c", c);
}
void set_X{char ach,int ax,int ay) {c=ach; x=ax; y=ay; }
};
, inline.
,
100
5.7.
:
- , ,
;
- ;
- .
.
:
class Y
{
public:
intx.y;
int ; char I;
II
voidprint(void);
void set_ Y{char al,int ax,int ayyint ak);
};
//
inline void Y::set_ Y{char al,int ax=40,int ay=15Jnt ak=15)
{ x=ax;
y-oy;
k=ak;
l=al;
}
/* print() ,
inline */
void Y::print
{ clrscrQ;
gotoxy(x,y);
for(int i=0;i<k;i++) printfC %c'\l)\
}
,
.
3.1. ( ).
, :
include <iostream.h>
#include <string.h>
class String II
{ private: char str[25]; II - 25
public:
II ()
void setjstr (char *); II
void displayjstr(void); II
char * returnjstr(void); II
};
//
void String::setjstr(char * s) { strcpy(str,s);}
void String::display_str(void) { cout str endl; }
char * String::return_str(void) {return str; }
101
,
,
include:
- - #include ;
- - #include
< >.
, ,
. :
< > < >
:
String , *, [6];
string , .
,
,
:
< >.< >: :< >.
:
a.String::str;
b'> String:: set_str{stl)\
c[i].String::displayjstrO.
, .
:
< >.< >;
< >->< >;
< >[]. < >.
:
astr
a,display_strO
102
b->str
b'>display_strO
cfij.str ;
fij.displayjstrQ.
3.1.
,
, , .
- .
.
.
.
,
.
:
-
main ;
-
, ;
- , ,
new delete.
.
,
.
, ,
.
:
1) ;
2) ;
3) C++
.
, pwW/c.
, private nprotected,
.
3.2.
#include <string.h>
#include <iostream.h>
#include <conio.h>
class sstro
{ public:
char strl[40];
int xy;
void setjstr{char *vs) II
103
voidmainO
{ sstro ={" \ 200, 400}; /*
*/
sstro bb,cc; II
bb.x=200; bb.y=150; //
strcpy(bb.strl, " 2''); //
cc.setjstr{"npuMep 3")\ /*
*/
aaprintQ; bb.printQ; cc.printO;
}
.
,
( - 3.2/
,
.
( 3.2).
this.
,
, .
this
:
<_> * const this = < _>.
,
,
. , this
() (. )
.
.
:
tMs->pole
tMs->str
this->fun().
,
this=&A, b - this=b.
. , this
,
.
104
3.1.
this .
,
, .
3.3. this.
Mnclude <iostream.h>
#include <conio.h>
class
{ int x,y;
publicvoid set (int ax, int ay) {x=ax;y=ay;}
voidprint(void) { coutx'
\t'
yendl\}
*funlO{x=y=100; return this;} /*
, */
/2( ) {-^-=.; -^=.; return *this;} /* 1
, */
};
voidmainQ
{ clrscrQ;
aa,bb;
aa.set(10,20);
bb.funl{y>print{);
II : 100 100
aa.printQ;
II : 10 20
aa.fun2(bb).print0;
II : 120
getchO; }
. - , -
.
.
,
.
.
,
static. ,
.
- ,
.
, < >::.
:
class point
{ intx.y;
105
3.1.
3.4. .
, ,
,
(. 3.1). first
, last - .
next .
drawAll(). drawAll()
next
^include <iostream.h>
Mnclude <string.h>
^include <conio.h>
Mnclude <alloc,h>
#mclude <stdio.h>
class String
{ public: char str[40]\
static String *Jirst; II -
static String *last; II -
String *next;
String{char *s)
{ strcpy(str,s);
next=NULL;
if(first==NULL)Jirst=this; else last'>next=this;
last=this; }
voiddisplayO { cout strendl;
}
static void displayAQ; //
};
String *String::/irst=NULL; II
String *String::last=NULL;
void String::displayAll Q //
{ String *p-first;
if(p=NULL) return;
^
first
a
next ^ ^
1 ^\
b
next I
1 -^n
last
1
11
do {p->displayO; p=P'>next;}
while(pl=NULL);
)
int main(void)
{ String ' "), II -
"),
' ");
if (String::first!-NULL) //
String:: display Alio;
getchO;
}
,
.
.
. C++ . ,
,
,
.
. ,
.
.
. .
, . ,
.
.
3.5. .
,
, .
#include <iostream.h>
^include <conio.h>
^include <graphics.h>
class Figura {
class Point II
{
intx,y,cv;
public:
int getxQ {return x;} II x
int getyO {return ;} II
int getcQ {return cv;} II
void setpoint(int ncv) II
108
3.1.
fcout'' :"
cinxy;
cv=ncv;}
endl;
};
class Line
II
{ Point ,; II
public:
void draw(void) II
{ setcolor(Tn.getcO);
line(Tn.getxOJn.getyOJk.getxO,Tk.getyO);}
void setline(int ncv) II
{ cout<<'' :'' endl;
Tn.setpoint(ncv); Tk.setpoint(ncv);}
voidprintQ
II
{coutTn.getxO'
'Tn.getyO'
';
coutTk.getxO'
' Tk.getyOendl;
}
};
//
int kolline;
II
Line *mas;
II
public:
void set/igura(int nJnt ncv); II
void drawfvoid);
II
void delfiguraQfdelete [] mas;} II
voidprintQ;
II
};
3.2.
,
,
.
. C++ ,
, ,
, .
, .
3.6.
. 1
, 3.2, strl.
sstr ,
,
.
^include <string.h>
^include <iostream.h>
^include <conio.h>
class sstr
{private:
char strl[40];
public: int x,y;
void print(void)
{cout" : " endl;
cout"x= "x"y=
"yendl;
cout'* : " endl;
cout" strl^"
strlendl;}
sstrfint vxyint vy,char *vs) // sstr
f int len=strlen(vs); II
if(len>=^0) {strncpy(strl,vs,40);strlf40J=W;}
elsestrcpy(strl,vs);
x=vx;y=vy; }
}:
voidmainQ
{ clrscrQ;
// sstr
sstr (200150,'' '');
aa.printQ;
getchQ;
}
,
,
. .
110
3.2,
.
3.7. .
Mnclude <string,h>
^include <iostream.h>
Mnclude <conio.h>
class sstr
{private:
char strl[40];
public:
int x,y;
void print(void)
{cout" / : " endl;
cout"x=
"x"y=
"yendl;
cout< < " strl="< <strl < <endl;}
sstrfvoid) II ,
fstrcpyfstrl/^KOHcmpyKmop "); =0;=; } ;
sstr (char *vs) II , strl
{int len-strlen(vs);
if(len>=40) {strncpy(strJ,vs,40);strlf40J=W;} else strcpy(strl,vs);
x=0; y-0; } // x no
sstr (char *vsyint vx) II , strl x
{int len-strlen(vs);
if(len>=40) {strncpy(strl,vs,40);strlf40J-=W;} else strcpy(strl,vs);
x=vx; y=0; } // no
sstr (char *vs,int vx,int vy) II ,
{int len-strlen(vs);
if(len>=40) {strncpy(strl,vs,40);strlf40J=W;} else strcpy(strl,vs);
x=vx;y==vy; }
}:
voidmainQ
{ clrscrQ;
sstr aO, al (" 1 no ");
sstr a2(" 2 "J00);
sstr (" 3",200,150);
aO.printQ;
al.printQ;
a2.print();
a3.print();
getchO;
}
,
, .
.
.
111
3.8.
.
^include <string.h>
include <iostream.h>
#mclude <conio.h>
class sstr
{private:
char strl[40];
public:
int x,y;
void print(void)
{ cout'' :" endl;
cout"x=
" x"
y= "
yendl;
cout" strl="
strlendl;}
sstr(char *vs,int vx,int vy); /*
*/
};
3.2.
,
.
,
, ,
, .
,
.
.
.
( ).
.
.
3.9.
.
^include <iostream,h>
Mnclude <conio.h>
class integ
{ int ;
public:
void print(void)
{ cout'' num=
"numendl;}
integ(int v):num(v){} II
integfvoid) {}
II
}:
class obinteg
{ integ ; II
public:
const intx,y,c; II
void print(void)
{ onum.printQ;
cout"x="
x"y=
"y"
color="cendl;}
obinteg(mt va,int vx,int vy,int vc):onum(va),x(vx),y(vy),c(vc){} I*
*/
obinteg(void) {}
II
}:
voidmainQ
{ clrscrQ;
integ {10); II
113
integsl;
lls\
obinteg bb(20,40,100,13); II
obinteg s2; II
" mtegsl" endl;
sLprintQ; II
" obintegs2*'endl;
s2.printQ; II
cout " integ: "endl;
aa.printQ; II
cout " integ:" endl;
bb.printQ; II
getchO;}
,
( 3.7), .
(
),
. , ,
, .
(
) .
.
,
,
.
C++
,
. , , ,
:
integ (2050,), =;
.
,
, :
Classl (const Classl&);
Classl(const Classl&,mt=0);
114
3.2.
.
,
- .
,
, .
,
:
< > (const < >&),
,
.
.
.
-
const,
const.
.
.
Mnclude <string.h>
#include <iostream.h>
^include <conio.h>
class child
{private: char *name; int age;
public:
void print(void)
{cout" : "name; cout":
"age
child(char *Name, int Age): name (Name), age (Age) {}
endl;}
};
voidmainO
{clrscrO;
("'\6),("'\5);
cout " : "endl;
aa,printQ; II : 6
bb.printQ; II : 5
child dd-aa; I* */
dd.printQ; II : 6
getchO;
}
115
3. Borland + + 3.1
3.10 :
child(const child & obj):name(obj.name),age(obj,age) {}
dd.
,
,
.
3.11. .
Mnclude <string,h>
#include <iostream.h>
Mnclude <conio.h>
class intpole
{ intcif;
public:
voidprint(void) { cout< < "cif="cif< < " "< < endl;}
intpole (intva) {cif=va;}
intpole(const intpole& obi) II
{
cifrobl.ciTS;}
};
class obpole
{ int ;
intpole intob; II
public:
void print(void)
{intob.printQ;
cout" num=
"numendl;}
obpole(int vn, int va):num(vn), intob(va) {}
};
voidmainQ
{ clrscrQ;
obpole aa(10,40);
cout " : "endl;
aa.printQ; II 40 10
obpole bb-aa; II
bb.printQ; II 120 10
getchO; }
obpole
:
obpole (const obpole &obj):num(obj.num) Jntob(obj.intob){}
116
3.2.
intob
intpole, cif
.
, ,
, ,
,
.
, ,
. , ,
, .
,
.
.
, ( 3.30).
.
, . 1 ,
- - ( ). ,
.
,
.
,
( 3.3).
. - ,
( 3.4).
.
, ,
. ,
(, , ..).
exit,
. ,
, abort . ,
, .
,
.
,
- ,
. ,
, ,
.
117
3.12. 1 .
^include <iostream,h>
#include <string.h>
class din_string
{ char *str; II -
unsigned size;
public:
dinjstring(char *s,unsigned SIZE=100); II
^dinjstringO; II
void displayQ{cout str
endl;}
};
3.3.
()
,
.
()
:
class < >:
< >{< >};
: private, protected,
public.
. 3.1.
3.1.
private
protected
private
public
private
private
protected
protected
public
protected
private
protected
protected
public
public
private
protected
public
,
private. ,
.
3.13. public.
^include <iostream.h>
Mnclude <conio.h>
class A
{private: // ()
int numza;
119
public:
II ()
int ;
void print (void)
{" "numzaendl;
cout " =
"numoaendl;}
() { numza=20; =50;}
};
class : public I* -
*/
f private: int numzb;
public:
void print (void)
{" =
"numzbendl;
' A =";
cout< <numoa< <endl;}
B(){numzb=100;}
};
void main()
{ clrscrQ;
A aa; bb;
cout " : "endl;
aa.print(); II : A = 20 = 50
bb.printQ; II : = 100 = 50
getchO; }
protected public
private. ,
,
.
3.14.
private.
#include <iostream.h>
Uinclude <conio.h>
class A
{private:
int numza;
protected: int numpra;
public:
int numoa;
void print(void)
{ cout " A =
" A=
cout " A =
120
"numzaendl;
"numpraendl;
"numoaendl;}
3.3.
.
,
.
: , ,
, - .
3.15.
.
^include <iostream.h>
^include <conio.h>
class A
{ int a;
public:
int cl;
voidprint(void) { cout< <a< < " "< < cl< <endl;}
A(int v):a(v){cl=10;} II A
;.
class : public A
{ int b;
public:
voidprint(void) { coutb
" "<<cl <<endl;}
B(int va,int vb):A(va),b(vb)ff II
};
class : public
{ int ;
public:
voidprint(void) { cout< <c< < " "cl < <endl;}
C(int va,int vb,int vc):B(va,vb),c(vc){} II
};
voidmainQ
{clrscrQ;
A aa(lO), *pa; II A
bb(10,100); // , -
(10,100,1000); II ,
cout " : "endl;
bb.cl=25; II 1
.1=35;
aa.printO;
II : 10
10
bb.printQ;
//: 100
25
cc.printQ;
//: 1000 35
122
3.3.
=&;
pa->printO: II : 10
10
pa=&bb; /*
*/
pa'>printQ;
II : 10
25
=&;
pa'>printO;
II 10
35
getchQ;
}
print()
,
.
print() .
( 3.4).
, ,
, .
,
, .
, ,
, ,
.
3.16.
.
, ,
. 3.2.
intuk
: int cifyole
:
Print, imtuk, -untuk
strb
: char*strl
: print, strb, -strb
strc
: char*str2
: print, strc, ---strc
. 3.2. 3.16
123
include <string.h>
^include <iostream.h>
#include <conio.h>
class intuk
{
int *ci^ole;
public:
voidprint(void) {cout'*ciJpole ="*ciJpole"
"endl;}
intuk(int va){cout"KOHcmpyKmop intuk"endl;
cifpole=new int;*cifpole=va;}
'-^intukO{cout " intuk''endl; delete cifpole;} };
class strb: public intuk
{ char *strl;
public:
voidprint(void) {cout"strl=
"strlendl;}
strb(int vUyChar *vs):intuk(va)
{ cout"KOHcmpyKmop strb"endl;
int l-strlen(vs); strl=new char fl-^lj; strcpy(strl,vs); }
^strbOfcout ''strb "endl;
deletestrl;}
};
voidmainQ
intuk aa( 10); II : intuk
strb (10/' 1 strb "); I* : intuk
strb */
strc (10/'. B'\ " 2 strc ");
I* : intuk
strb
strc */
cout " : "endl;
aa.printQ;
II : cifpole =10
bb.printQ;
II : strl= 1 strb
cc.printQ;
II : str2=o6beKT 2 strc
} /* ,
:*/
124
3.3.
. C++
, .
.
.
:
class < >:
< 1>,
< 2>,
< >{...};
. ,
.
,
.
. ,
:
< >(< >):
< 1>(< >).
< >(< >)
{< >}
, ,
, ()
.
,
:
(
),
.
3.17. .
Mnclude <iostream.h>
Mnclude <conio.h>
^include <stdlib.h>
class fixed
{ int numfic;
125
public:
fixed(int v):numjx(v) {cout'' flxed\n";}
}:
class integral
{ public:
int numfic;
integral(int va) :numfic(va) {cout< < " integ\n ";}
};
class rational
{public:
char ; int ;
rational(int vn):num(vn) {cout" rationahn";}
}:
class twonasL'private integral, II
public rational II
{private: fixednumfix; II
public:
twonasl(int nfi, int nm^char vc, intpnfic):
integral(nfic), rational(nm), numfix(pnfic)
{cout" twonaslW;
c=vc; II
}
II
int get(void) II ,
{return numfic;} // integral private
};
voidmainQ
{clrscrQ; randomize;
int r=random(100)-50;
twonaslaa(rM 'R\50);
coutaa.getO'
'aa.c'
'aa.numendl;
}
twonasl :
- numfx, integral ( public^
private, , private),
-50 49;
- , rational ( public,
public, ,/?w6/zc),
20 R, rational
, twonasl;
- fixed numfix,
nmnfx, twonasl,
50.
126
3.3.
integ
rational
fixed
twonasl
numfx ( integral), ,
twonasl:
-49R20
.
.
,
(. 3.3). ,
.
, .
:
188< >:
virtual < >{...};
,
, .
:
. 3.3. Base
127
,
, -
. .
,
- .
3.18. .
^include <iostream.h>
class fixed
{ protected: int Fix;
public:
fixed(void)
II
{ cout " fixedW;}
fixed(int fix):Fix(fix) II
{ " fixed int\n";}
};
class derived_l .virtual public fixed II
{public:
int One;
derived 1 (void) { cout< < " 1 \n ";}
h
class derived_2: virtual private fixed II
{public:
int Two;
derived_2(void) {cout" 2\n";}
}:
class derived: public derived_l, /* */
public derived_2
{public:
derived(void){cout"
derived W;}
derived(int fix):
fixed(fix) { cout< < " derived int \n ";}
void Out() { cout" Fix =" Fix;}
};
mainQ {derived Var(lO); Var.Out(); }
:
fixed int
1
2
derived, int
oeFix=10
128
3.4.
, , Fix
derived :
derived_l::Fix
derived_2::Fix.
3.4.
1.5,
,
. ,
, ,
.
() C++
( )
. C++
, , ,
(
).
,
,
.
3.15. print()
. ,
show(), print()
.
3.19. .
Uinclude < iostream. h>
^include <conio.h>
class A
{ int a;
public:
voidshowQ{cout" : ''endl;
printQ;} //
voidprint(void)
II
coutaendl;}
A(intv):a(v){}
};
129
class : public
{ intb;
public:
voidprint(void) ) II
{ coutbendl;}
B(int va, int vb):A (va), b(vb) {}
};
class C: public
{ int ;
public:
voidprint(void) //
{ coutcendl;}
(int va, int vb, int vc) :B(va, vb), c(vc) {}
};
voidmainO
{clrscrQ;
A aa(20); bb(lOJOO); cc(50,200,3000);
cout " : "endl;
II printO
aa.printQ; II : 20
bb.printQ; //: 100
cc.printQ; II : 3000
getchO;
II printO
aa.showQ; II : 20
bb.showQ; //: 10
cc.showQ; II : 50
getchO;
}
, print()
. , show(),
, print(). show()
. ,
, show(),
printO ,
.
.
.
.
,
virtual
130
3.4.
() .
,
, ,
, , .
, .
.
-- ,
,
.
,
, ,
, ,
: . ,
,
,
.
,
virtual
print() .
3.20. .
Mnclude <iostream.h>
^include <conio.h>
class A
{ int a;
public:
voidshowQ {" o6beKma*'endl;printQ;}
virtual voidprint(void) II
{
coutaendl;}
A(intv):a(v){}};
class B: public A
{ intb;
public:
void print(void) II
{
coutbendl;}
(int va, int vb) :A (va), b(vb) {}
};
class C: public
{ int ;
public:
void print(void) II
{
coutcendl;}
131
3.4.
, ,
.
. ,
, ?
.
,
. .
, .
C++
.
,
, .
:
virtual <_>(< >)=0
=0 - .
,
, , .
, , ,
, .
.
.
. ,
,
, .
, ,
, .
3.21.
.
, . 3.4.
Tpole
:
int*pnum
: print
11
:
virtual printO=0
Tstrpole
:
char*str
: print
. 3.4. 3.21
133
#incliide <string.h>
^include <stdio.h>
#incliide <stdlib.h>
Mnclude <iostream.h>
class Tpole II
{public:
virtual voidPrint(void)=0; II
TpoleOO
-TpoleOO
}:
class Tnumpole:public Tpole
{private: int "^pnum;
public:
Tnumpole (int n) {pnum=new int; *pnum=n;}
--Tnumpole (void) {delete pnum;}
void Print(void) //
{printf(*'\n - %d'\*pnum);}
};
class Tstrpole.public Tpole
{ private: char *str;
public:
Tstrpole(char ^^st);
--Tstrpole(void) {delete str;}
voidPrint(void){printf("\n - %s",str);} /*
Tstrpole*/
}:
inline Tstrpole:: Tstrpole (char *st)
{int I; l-strlen(st); str=new charfl+lj;
strcpy(str,st): }
void mainQ
{intnj;
char Stf80];
Tpole "^aflOJ; II Tpole
for(i=0;i<10;i+-^)
{if(i%2)
{printfC'\neeedume : "); scanfC*%2d'\&n);
afij=new Tnumpole (n);} II Tnmnpole
else
{printf("\neeedume < 80 : "); scanf("%s",st);
afij=new Tstrpole (st);} II Tstrpole
;
puts("\n ");
for(i=0;i<10;i++) {a[i]->Print();
}
134
delete a[i];}
3.5,
10 ,
Tpole,
.
.
.
3.5.
( 3.1),
(private), (protected)
(public) .
,
.
.
.
,
.
.
.
, ,
, ,
. .
friend.
.
3.22. .
include <iostream.h>
Mnclude <conio.h>
class FIXED
{private:
int a;
public: FIXED(int v):a(v){}
friend void show(FIXED);
};
II
}
135
voidmainQ
{ clrscrQ;
FIXED aa(25);
cout " :
show(aa); //: 25 35
}
"endl;
.
,
, .
3.23. - .
^include <iostream.h>
^include <conio.h>
class FLOAT; //
class FIXED
{private:
int a;
public:
FIXED(intv):a(v)f}
double Add(FLOAT);
voidprint0 {cout a endl;}
};
class FLOAT
{private: double b;
public:
FLOAT(double val){b=val;}
void print 0 {cout b endl;}
friend double FIXED::Add(FLOAT); /*
FIXED FLOAT */
};
double FIXED::Add(FLOATPar)
{return a+Par.b;} /*
FLOAT */
voidmainQ
{ clrscrQ;
FIXED aa(25); FLOAT bb(45);
cout " : "endl;
coutaa.Add(bb)endl;
//: 70
aa.printQ; II : 25
bb.printQ; II : 45
getchQ;
}
136
3.5.
.
this.
( ).
,
(public, protected, pri
vate).
.
.
. ,
. ,
.
,
, ,
C++.
,
,
:
friend class < >.
3.24. .
^include <iostream.h>
^include <conio,h>
class SHOW; II
class PAIR
{private:
char *Head, *Tail;
public:
PAIR(char "^one, char *two) :Head(one), Tail (two) {}
friend class SHOW; II
};
class SHOW /* SHOW
PAIR*/
{private: PAIR Twins;
public:
SHOW(char *one,char *two):Twins(one,two){}
void HeadO{cout Twins.PAIR::Head endl;}
void TailO{cout Twins.PAIR::Tail
endl;}
};
voidmainQ
f clrscrQ;
SHOWaaC'HELLO", "FRIEND");
137
cout '^ :
aa.HeadQ; //: HELLO
aa.TailQ; //: FRffiND
getchO;}
"endl;
3.6.
C++ ,
.
, ..
. C++
.
, .
.
operator ( @ - ).
-. - , .
:
( ) -, :
( ) ( );
( ) -,
,
( ) (
- ).
- . 3.2.
3.2. -
< >1 @
()
< pe3ynbTaTa>operator @
(<1>, <2>)
< pe3ynbTaTa>operator @ ()
@ - ,
< > - ( ,
, ).
,
- *,sizeof,?:,#,##,::,class::;
- =,[],() ;
- = ;
- (
).
138
3.6.
- ,
. 3.3.
3.3. -
operator @ (<1>)
operator @
(< 1 >,<2>)
<apryMeHr>.operator@0
< 1 >.operator@
(<2>)
@<>
<1 >@<2>
@<>
< 1 >@<2>
-
. , -
,
^/(^, .
, ,
.
.
3.25. - .
include <string.h>
^include <iostream.h>
^include <conio.h>
class sstrll sstr
{private: II
char "^str;
int len;
public: II
void print(void)
{cout"CodepoicuMoe : " endl;
cout":
"strendl;
cout<< " : "<< lenendl;}
sstrQO;
sstr(char *vs)
{len=strlen(vs); str=new charflen+lj; strcpy(str,vs); }
--sstrQ {delete str;}
friend sstr & operator \-(sstr &ySStr & ) ; /* + */
};
sstr & operator +(sstr &, sstr & ) II -
139
{ int I - +.1;
char *s;
s=new charfl-^lj; strcpy(s,A.str); strcat(SyB.str);
sstr *ps=new sstr(s);
delete []s;
return *ps; }
voidmainQ
sstr (" ");
sstr ' ");
sstr cc=aa+bb-^" "; II
cc.printQ;
sstr dd;
dd=operator +(aa,bb); II
dd.printO;
getchO;}
- ( )
,
.
3.26. -.
#include <string.h>
^include <stdio.h>
#include <iostream.h>
^include <conio.h>
II sstr
class sstr
{private: II
char *str;
int len;
public:
void print (void)
{cout"
: " endl;
cout " : "< <str< <endl;
cout<< " : "<< lenendl;}
sstrOO
sstr(char *vs) flen=strlen(vs); str=new charflen-^lj; strcpy(str,vs);}
--sstrO{delete str;}
sstr & operator +(sstr &); /* ,
+*/
sstr & operator -Q; /* ,
- */
};
140
3.6.
sstr& sstr:.-operator -Q /* */
f char ;
for (int i=0;i<=len/2-l;i'h^){c=strfiJ; str[i]=str[len'i'l]; str[len-i'l]=c;};
return *this;
}
sstr & sstr::operator +(sstr &A) /*
- */
{int I =A.len+len;
char *s; s=new char[l-\-l];
strcpy(s,str);
strcat(s, A.str);
len=l; str=s;
return *this; }
voidmainQ
{ clrscrQ;
sstr aa(" ");
sstr ' ");
sstr cc=aa+bb; II
.print ;
sstr dd; dd=aa.operator\-(bb); II
dd.printQ;
-; -bb; II -
aa.printQ;
.print ();
getchO;}
.
3.27.
+.
Mnclude <iostream.h>
^include <conio.h>
class point
{ float x,y;
public:
void print(void)
{ cout"
: " endl;
cout"x
="x"y=^
"yendl;}
pointQU
point (float axjloat ay) :x(ax),y(ay) {}
point & operator -^(point &p) II +
{point *pp-new point;
pp->x=x+p.x; '>=+';
141
return *; }
friend point & operator*(float k,point &p) /*
*/
{ point *pp=new point;
->=. *;
->=' *;
return *;
}
friend point & operator*(const point i&pjloat ) /*
*/
{ point *pp-new point;
pp'>y=p.y*k;
'>=.*;
return *; }
};
voidmainQ
{ clrscrQ;
point p(2,3),r(4,5),q,
q =p. operator+(r) ;
II
q.printQ;
// : 6 8
q=p^r:
//
q.printQ;
// : 6 8
q=r+p:
//
q.printQ;
// : 6 8
q=operator *(5,p);
//
q.printQ;
// : 10 15
q=p*5;
//
q.printQ;
// : 10 15
q=5^p;
q.printQ;
// : 10 15
}
-
C++ , -
( ) ( )
. ,
,
.
:
osrteam & operator(ostream & 1,< 1> <>)
{< ->};
istream & operator (istream & ,< > &<>)
{< ->}.
, , /?r/V(2/e viprotected^ .
142
3.6.
3.28. -.
^include <iostream.h>
#include <conio.h>
class TAdress
{private:
char country[16\;
char city[16\;
char street[20];
int number_of_hoiise;
public:
TAdressOO
-^TAdressOO
friendostream& operator (ostream &out,TAdress obj);
friendistream& operator (istream &in,TAdress &obj);
};
3.7.
C++,
-
! - .
(, , ..). ,
, C++
,
(
).
, ,
.
() .
, ( new de
lete) .
.
, ,
:
- ;
- ;
- .
C++,
.
. C++
,
.
,
new. ,
new, ,
, .
,
. new
,
. -
, (NULL).
, new, delete
.
144
3.7.
^, ,
.
, , (,
).
, , ,
.
.
, .
.
,
,
.
,
.
3.29.
.
Mnclude <string.h>
^include <iostream.h>
#include <conio.h>
class Tmass
{public:
int *mas; II ~
int size; II
voidprint(void);
Tmass 00;
Tmass(int Size);
--Tmass0 {delete []mas; II
cout< < " "< <endl;}
};
Tmass:: Tmass (int Size)
{ cout< < " "endl;
mas^new intfSizeJ; II
size=Size;
cout" " size;
cout" "endl;
for(int i=0;i<size;i-\-+) cinmas[i];
}
void Tmass::print(void)
145
3.7.
{ private:
char * country;
char * city;
char * street;
int number_ofJtouse;
public:
TAdress(TAdress &a) II
{cout"
"endl;
country-new charfstrlen(a.country)-^lJ;
city=new charfstrlen(a.city)HJ;
street=new charfstrlen(a.street)-^lj;
strcpy(country,a.country);
strcpy(city,a.city);
strcpy(street,a.street);
number_of__house='a.number_of_house; }
TAdressQ {cout"
"endl;
country=NULL; city=NULL; street=NULL;}
-^TAdressQ
f cout''
'^endl;
delete [] country; delete [] city; delete [] street; }
TAdress& operator =(TAdress &obj) /*
*/
{ if (country!-NULL) delete [] country;
country=new charfstrlen(obj.country)+lJ; strcpy(country,obj.country);
if(city!=NULL) delete [] city;
city=new char[strlen(obj.city)-^l]; strcpy(city,obj.city);
if(street!=NULL) delete [] street;
street=new char[strlen(obj.street)-^l]; strcpy(street,obj.street);
number_of_house-obj.number_ofJtouse;
return *this; }
friendostream& operator (ostream &out,TAdress obj);
friendistream& operator (istream &in,TAdress &obj);
};
ostream& operator (ostream &out,TAdress obj)
{out":
"endl;
out"Country:
"obj.countryendl;
out< < " City : "< <obj, city endl;
out"Street
:
"obj.streetendl;
out"House
:
"obj.number_of_houseendl;
return out; }
istream& operator (istream &in,TAdress &obj)
{ char str[40\; int I;
147
cout^* :^;
cout^^ , , , **; coutendl;
instr;
l-strlen(str);
if(obj.country!=NULL) II ,
delete [] obj.country; II -
obj. country-new -^!]; strcpy(obj. country,str);
instr;
i=strlen(str);
if(obj.city!=NULL) II ,
delete [] obj. city; II -
obj.city=new charfl-^lj; strcpy(obj.city,str);
instr;
l=strlen(str);
if(obj.street!-NULL) II ,
delete [] obj.street; II -
obj.street=new charfl-^lj; strcpy(obj.street,str);
inobj.number_of_house;
return in;
}
void mainQ
{ clrscrQ;
TAdress a,b,c;
cinab;
coutab;
getchO;
c=a; II
coutc;
a=b;
II , ,
*/
couta;
getchO;
}
. ,
.
. ,
, .
, .
, , ,
.
(. 3.30).
148
3.7.
.
, .
(
).
.
,
New:
<__> = new <_>;
<_yaae_a_oe>=new<_acca>(<cco_apaepo>);
.
delete :
delete < >;
3.31. .
#mcltide <iostream,h>
^include <iomanip.h>
Mnclude <conio.h>
class TVector
{private:
intx,y,z;
public:
TVector 0 {cout< < '' "< <endl;}
TVector (int ox, int ay, int az)
{cout""endl;
x=ax;y=ay;z=az;}
-TVector 0 {cout< < " "< <endl;}
voidPrintVecQ;
}:
void TVector::PrintVecQ
{" : "setw(5)x",
";
coutsetw(5)y",
"setw(5)z"\n";
}
voidmainQ
{ TVector *a, *b; II
clrscrQ;
II
a=new TVectorfl2,34,23); II
b=new TVector(10,45,56); II
149
3.7.
#include <string.h>
#incliide <iostream.h>
^include <conio.h>
class sstr
{private: char strl[40];
public:
intx,y;
void print(void)
{cout"
codepjfcuMoe : " endl;
cout"x=
"x"y=
"y"
strl=
"strlendl;}
sstrQ {cout' ' ' 'endl;}
sstrfint vx,int vy,char *vs); II
sstr {cout< < " "endl;}
void setstrfint ax,int ay,char *vs); II
};
, . ,
C++ ,
.
, :
- ,
, ( 1.25).
() ;
- ,
,
,
.
.
virtual,
. delete
.
( 3.4)
3.33.
. : ,
,
,
, .
^include <iostream.h>
#include <conio.h>
<stdlib,h>
class integ
{protected: int n;
public:
virtual voidprint(void) { cout<< " "<<nendl;}
integ(int vn) {cout< <' " integ"< <endl; n =vn;}
virtual ^integO {cout^^ integ**endl;}
};
3.7.
};
,
, .
, ,
.
, (
),
.
3.8.
-- .
. (template),
.
,
, .
, , ..
() . ^ :
template < > < >
,
, , .
, ,
class.
3.34. ,
.
template < class type> II type
class array II array
{ type * contents; II type
int size;
II
public:
array(int number) {contents = new type [size=number];}
---array 0 {delete [] contents;}
type & operator [] (intx) II []
{ \f((^^0) 11 (x> =size)) { cerr < < " "; x=0;}
return contents[x];
}
} II array
154
3.8.
, array
. ,
, .
, ,
:
__ <__>
_ ()
, , 3.34,
:
array <int> int_a(50); // -
array <char> char_a(100); // - char
array <float> float_(30); // - rmiafloat
,
,
, .
3.35.
.
#include ''array.h"
^include <stdlib.h>
Mnclude <stdio.h>
#include <iostream.h>
voidmainQ
{inti;
array<mt> int_a(5);
array<char> char_a(5);
for (i=0;i<5;i+-^) II
{mt_a[i]=random(20); char_a[i]: = 'A '+i;}
puts ('' ");
for{i=0;i<5:i++)
{cout " " int_a[i] " "
charjafijendl;}
}
, ,
- ( ),
:
template <class type> type & array < type>::operator[](intx) /*
- */
{ \f((^^0) 11 (x> =size)) { cerr '' '';x=0;}
return contents [x];
}
155
.
. -
, .
, ,
,
. .
:
template < > < >
class,
(). ,
, ,
:
template <class type> type max(type x,
typey){return(x>y)?x:y;}
,
, .
, ,
, . ,
,
, , >
, .
,
- > .
3.36.
.
#include <conio.h>
include <string.h>
#mclude <iostream.h>
template <class T> T max(Tx, )
freturn(x>y) ?x:y;}
char * maxfchar *x, char *y) /*
*/
{return strcmp(x,y) > ? :;}
void main ()
{ clrscrQ;
int a=lb=2;
char c='a', d='m'; float e=]23.675,f=456;
charstrfj="abcd'\ str2[]="abnd";
//
156
3.8.
cout
cout
cout
cout
getchO;
}
^'Integer = ''max(a,b)
endl; II Integer max= 2
"Character max= "max(c,d)
endl; II Character max= m
"Float max= "max(ej)
endl;
II Float max= 456
"String max= "max(str,str2)
endl; II String max= abnd
.
. ,
.
.
.
3.37. (
)
.
: ,
, , ,
,
.
[ .
,
,
.
: -,
.
-,
.
type (. 3.5).
.
, .
char .
#include <iostream.h>
#include <conio.h>
157
char
. 3.5. 3.37
Mnclude <string.h>
template < class type> II type
class Tset
{private:
type *contents; // type
int size;
//
int sizetek;
//
int SetEl(int ind,type ) II
{ if(ind<size) { contents[ind]=m;sizetek+-l;return 1;}
else {cout'^ "endl; return 0;} }
type GetEl(int ind) II
{return contents [ind];}
public:
TsetQ { cout< < " no "< <endl; contents =NULL;}
Tset(Tset &A);
II
Tsetftnt number) II Tset
{ cout< < " "< <endl;
contents = new type fsize=numberj;sizetek=0;}
--Tset 0
II
{cout""endl;
delete [] contents;}
int GetsizeQ //
{return size;}
voidAdd(typem); //
void Del(type ); II
int In(type );
II
int InSet(int Nn); II
void OutSetQ;
II
Tset& CrossSet(Tset &); II
Tset (Scoperator +(Tset &); II
Tset (Scoperator =(Tset &); II
friend Tset &operator *(Tset &A, Tset &B); II
friend Tset &operator -(Tset &A, Tset &B); II
};
158
3.8.
3.9.
3.9.
.
,
, .
, , .
.
C++
.
.
,
.
- .
,
.
, ,
, ,
.
,
, ,
! .
-
. .
.
,
.
3.38.
.
, - .
.
- .
~ - :
,
. .
-
,
161
^1|||
1
: st[40]
: Print
: str[20]
: Print
iBiilii!
:
Sort, Compare
:
Compare
. 3.6. 3.38
162
:
first, last, cur
:
Add, Del,
ForEach
3.9.
public:
void Add(TElement *e);
II
TElement *Del(void);
II
void ForEachfvoid ("^fi(TElement *e)); /*
*/
TSpisok(void) {first^last^cur^NULL;}
virtual ^TSpisokOfputsC*yHU4mo:Mumh .'');}
};
void TSpisok: :Add(TElement "^e)
{if(first==NULL) first=last=e;
else { e->suc=first; first=first'>pre=e;} }
TElement *TSpisok::DeI(void)
{ TElement *temp;
temp=last;
if(last!=NULL) {last=last->pre;
if(last!=NULL)last'>suc=NULL;}
if(last==NULL)first=NULL;
return temp;
}
void TSpisok::ForEach(void (''^fi(TElement "^e))
{cur=first;
while (cur!=NULL) {(*f)(cur); cur=cur->suc;} }
class TSortSpisok:public TSpisok II
{protected:
virtual int Compare(void *opl,void *op2)=0; /*
1 */
public:
void Sort(void);
II
TSortSpisok(void):TSpisokO{} //
'^TSortSpisokQ
II
{putsC'yHU4Ho:Hcumb .");}
};
void TSortSpisok: :Sort(void)
{int swap=l;
TElement "^temp;
while (swap)
{swap=0;
cur=first;
while ('>sue!-NULL)
{if (Compare(cur,cur'>suc))
{temp=cur'>suc; cur'>suc=temp'>suc; temp->suc=cur;
if (cur->pre!-NULL) cur->pre->suc-temp; else first-temp;
temp- >pre=' >pre; cur- >pre=temp;
if(cur->suc!=NULL) cur'>suc->pre=cur; else last=cur;
cur-temp;
swap=l;
}
163
3. Borland + +3.1
else cur=cur->suc;
}
}
Mnclude <string.h>
class TNum: public Telement II
{public:
int num;
II
virtual voidPrint(void) {printfC %d " ,num);}
TNumQ {}
II no
TNum(int n):num(n) {} II
^TNum(void) {putsC .");}//
};
164
3.9.
: num
: Print
: *st
: Print
: *contens,
size, n
: arrayob,
-arrayob,
operator[ ],
add,
sizeofitnas
. 3.7. 3.39
#include <string.h>
#include <iostream.h>
^include <stdlib.h>
Mnclude <conio.h>
template < class type> II type
class arrayob II arrayob
{type **contents; II type
int size;
II
int ;
II
public:
arrayob(int number) {contents =new type * [size=number];}
^arrayob Q;
voidadd(type *p)
{ if(n==size)cerr" "; II
else {contents[]-; ++;} }
type & operator [] (intx) II
{if ((x<0)\\(x>=size)) {cerr *'
"xendl;x=0;}
return *contents[xJ;}
int sizeofmasQ {return n;} II
};
3.9.
4. WINDOWS
Win32
,
Delphi +-- Builder. : Windows
, ^
. , ^,
,
.
. , , ,
^ Windows,
.
4.1. Windows
MS DOS
. ,
,
, , , . , ,
,
, MS DOS ,
, (. 4.1). ,
.
MS DOS . ,
MS DOS
,
.
. ,
:
1)
;
169
4. - Windows
:
1)
.
2) .
3) .
4) .
5) .
6) .
MS DOS:
1)
2)
3)
BIOS
, 4.1. MS DOS -
IBM PC
2) (
, , VGA );
3) ,
.
Windows
MS DOS ,
.
.
Windows, \Wn32: Windows'95, Windows'98,
Mndows NT.
Windows , , ,
, 32- ,
16- ,
Widows.
Win32 :
Windows'95 Windows'98
, .
Windows NT, -
,
Windows'95 Windows'98
, ,
, Windows NT.
Windows'98 Windows'95
, ,
InterNet, .
Win32 :
170
4.1. Windows
1. 4
Win32.
32- 4
. Win32 , Win32
4 ,
2 ,
2 - .
,
.
,
.
2. /
().
, ..
, ,
.
. . 32
, ,
1
() ,
Win 16, ,
,
,
.
,
, Win32
.
,
.
3. .
, , MS DOS.
Windows,
,
.
, - . ,
, , .
,
, .
171
4. Windows
.
4. ( -
).
. Win32
. ,
, Windows-,
.
- ,
Windows.
5. .
OLE {Object Linking end Embedding ) - ,
(
, ).
:
- -
, ,
;
- ,
,
.
OLE- , ,
Word , Paint, Excel.
6. .
Windows ,
MS DOS
MS DOS,
, Windows.
, ,
Windows ,
(. 4.2).
API
{Application Program Interface - ) , -
, , ..
,
.
172
4.1. Windows
Windows
1.
Windows
1.
. 4.2. Windows
API
DLL {Dynamic Link Library ).
,
.
.
,
.
, .
.
DLL
.
Windows . , , ,
MS DOS. MS DOS ,
, :
1,
(. 4.3).
.
MS DOS
BIOS
^
-
. 4.3. MS DOS
173
4. Windows
( )
Windows ,
, ^
, .
, , :
(
), , ,
, ,
,
..
,
, ,
, ,
.
,
,
.
. Windows
, ,
, .
, ,
Windows ,
. ,
.
, , ,
,
,
, .
Windows, ,
,
.
Windows
1
2
^
. 4.4. Windows
174
4.2. / Windows
, , ,
,
(. 4.4).
, ,
Windows, Windows,
4.2. Windows
Windows . (. 4.5),
.
,
,
.
, -
, (, ,
..) 1 ,
,
.
, A\^dows
: .
.
.
,
.
, .
Windows .
Windows
(. 4.6) .
/^ .
X =|
-
. 4.5. Windows'95
175
4. Windows
Windows
Windows
. 4.6.
.
, Windows
.
.
,
( ,
, )
.
Windows .
32- ,
, , WM_CHAR (
), WM_PAINT
( ), WM_CLOSE
( ), WM_TIMER (
) . .
32-
, ,
.
, (
)
WM_CHAR (,
). ASCII-
, ,
, scan-.
, ,
, Alt ..
176
4.2. Windows
Windows
Windows
/WM.CHAR
V.
^
Lrr,
, /
V.
14.
""""*v
)
"^ ^
^
. 4.7.
, ,
1, , , ,
(. 4.7).
, ,
- (
),
.
,
, , ..
, .
, , ..
,
.
. Windows
:
( Windows ) (
) ^ ;
(
, );
(
).
, , Windows,
.
WM^DESTROY (. 4.8),
.
177
4. Windows
Windows
Windows
WM DESTROY
. 4.8. WM_DESTROY
,
API, ,
WM_QUIT, .
,
.
4.3, Windows
Delphi C+H-Builder
, . . ,
API
.
.
M^dows, -
.
Visual C++, Delphi, C++Builder,
Windows.
,
,
.
.
Visual C++ yq)ca
, , , .
C++ Delphi C++Builder .
Visual C++
.
178
4.3. Windows
Delphi CH-+Builder
VCL (Visual Component Library -
). :
Delphi Object Pascal, C+-f-Builder,
, C++. .
, ,
: -, - () -.
-, .
-
.
VCL.
TForm.
VCL - ,
(.. - , ,
..) .
,
TForm (. . 4.15).
,
.
(. 4.9).
,
( TAplication),
.
( TForm 1, TForm)
, ..
, ,
.
,
, ,
.
,
TForm, - ,
.
,
.
,
.
179
4. Windows
View/ Project
Run
Component
Database/ Jools
Workgroups
Help
g^r
^
HI-IE3
1 """|'1>|
Fonn1:TForm1
Properties
][JIZ1
Events
ActiveControl
AutoScroli
True
bSorderlcons
[biSystemMen
BorderStyle
bsSizeable
Caption >Form1
ClientHeight
CllentWidth
Color
1 Ctl3D
189
290
clBtnFace
True
nUL
'
( )
1: 1
Modified
Insert
'
( )
. 4.9. Delphi
TForm WM_CHAR.
, ,
:
1) OnKeyPress - ,
ASCII ( - -
);
2) OnKeyDown OnKeyUp - ,
, ,
(. 4.10).
, 1 C++Builder
^
.
, ,
,
,
Events (). , ,
Form
):
$0
4.3. Windows
WM_CHAR
^
KeyDown
KeyUp
KeyPressed
. 4.10.
:
OnCreate - -
( );
OnActivate - (
^! );
OnShow - () ;
OnPaint - ;
OnResize - ;
OnDeactivate - (
);
OnHide - ( );
OnCloseQuery - -
- ;
OnClose - ;
OnDestroy - ;
:
OnKeyPressed - , ASCII;
OnKeyDoun, OnKeyUp - ,
, ASCII;
OnCIick, OnDblClick -
;
OnMouseMove - ();
OnMouseDown, OnMouseUp - ;
:
OnDragDrop - ;
OnDragOver -
();
;
OnHelp - ;
OnCbange - .
,
, ( TLabel) 9 :
181
4. Windows
4.3. Windows
:
^
\
Hi-iia
1 ||
:
|4489
. 4.11.
3. ,
(. 4.12).
4.
. :
.
(. 4.13).
. 4.12.
183
4. Windows
1
.
1.
DelpM.
)
, ,
(. 4.14).
TForml,
TForm,
4.13. ,
.
)
KOMHoneirr :
Forml:
Name:=MainForm;
:=' ';
Labell:
Name:='InputLaber;
:=' ';
Label2:
Name:=OutPutLabeI;
11:=' :';
Editl:
Name:=InputEdit;
EdU2:
Name:=OutPutEdit;
Enable:=false;
ReadOnly:=true;
JL
y*'
4.3. Windows
9^^ 1111111111111111
lllljl^^^^^^^^^^^^^^^^^^
1111
111||
^^^^^^^^^^,
Form Activate
TMainForm
InputEditKeyPressed
NextButtonClick
ExitButtonClick
ilBillli
. 4.15.
Buttonl:
Name:=NextButton;
1:='';
Button2:
Name:=ExitButton;
1:='';
TMainForm,
, . 4.15.
) (
), ,
(. 4.16).
,
.
^^^)-^
(^,
:
1 -
2 - Enter
-
4 -
5 "
. 4.16.
185
4. Windows
1 - (OnFormActivate)
,
. 4.11, ( ,
,
).
2 - Enter
(OnKeyPressed ) .
, . 4.11,
(, ,
).
, ,
. 4.11, .
- ( Click
) .
4 - (On Click
)
, . 4.11, .
- .
) ,
: 1 MessageDlg.
2.
Delphi ,
.
.
, ,
, :
Unit MainUnit;
Interface
Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dia
logs, StdCtrls, ExtCtrls;
Type TMainForm = classfTForm)
{ }
Bevel 1: TBevel;
{}
NextButton, ExitButton: TButton; { }
Input Label, OutPutLabel: TLabel; { }
InPutEdit, OutPutEdit: TEdit; { }
procedure FormActivate(Sender: TObject); {
}
procedure InPutEditKeyPress (Sender: TObject; var Key: Char);
{ Enter
}
186
4.3. Windows
4. Windows
MessageDlgC . \
mtError, [mbOk], 0); { }
end
End;
{ }
Procedure TMainForm.NextButtonClick(Sender: TObject);
Begin
FormActivate(NextButton); {
}
End;
{ }
Procedure TMainForm.ExitButtonClick(Sender: TObject);
Begin Close; { }
End;
End.
()
Delphi :
Program Example!;
Uses Forms, MainUnit in 'MainUnit.pas' (MainFormj;
{$R *RES}
Begin
Application. Initialize;
{ }
Application.CreateForm(TMainForm, MainForm); {
}
Application.Run;
{ }
End
:
*.dpr - - Pascal (
);
*.pas - , (
);
*.dfin - .
- .
.
4.2. ( 2).
C++ Builder,
,
TMainForm C++ MainUnit.h:
mjhde/MainUnitH
Mefine MainUnitH
188
4.3. Windows
^include <Classes.hpp>
Mnclude <Controls,hpp>
#include <StdCtrls.hpp>
^include <Forms.hpp>
^include <ExtCtrls.hpp>
class TMainForm : public TForm
{
_ _published:
II , ( VCL)
TLabel VnputLabel;
TLabel *OutPutLabel;
TBevel ""Bevell;
TEdit 4nputEdit;
TEdit *OutPutEdit;
TButton *NextButton;
TButton *ExitButton;
void _ Jdstcall FormActivate(TObject *Sender);
void J'astcall InputEditKeyPress(TObject ^Sender, char iScKey);
void _ Jastcall NextButtonClick(TObject ""Sender);
void _Jastcall ExitButtonClick(TObject ^Sender);
private:
II
public:
II
_ J'astcall TMainForm(TComponent* Owner);
};
NextButton->Enabled=false; II
InputEdit'>Readonly =false; II
189
4. Windows
InputEdit'>Enabled=true;
II
InputEdit'>ClearO;
II
InputEdit'>SetFociis();
II
OutPutEdit'> Visible =false; II
OutPutLabel'> Visible=false; II
}
// Enter
void _ Jdstcall TMainForm: :InputEditKeyPress(TObject ^Sender,
char &Key)
{float x;
if (Key=-*\r')
II ,
fKey='\0';
II
try
II ,
{x=StrToFloat(InputEdit'>Text); II
InputEdit->Readonly=true;
II
InputEdit'>Enabled=false;
II
OutPutLabel'>Visible=true;
II
OutPutEdit'> Visible-true;
II
OutPutEdit'>Text=FloatToStr{x*x); II
NextButton->Enabled=true;
II
NextButton'>SetFocusO; II
;
catch (EConvertError&) II
{TMsgDlgButtons SI; //
SlmbOK;
// S1
MessageDlg(*'CmpoKa . '\
mtError, SI, 0);
II
}
}
}
II
void _ Jastcall TMainForm: :NextButtonClick(TObject "^Sender)
{ FormActivate(NextButton); II
//
void_ Jastcall TMainForm::ExitButtonClick(TObject ^Sender)
{ CloseQ;}
II
Example l.cpp C++Builder :
#include <vcl.h>
^pragma hdrstop
USERESC'Example 1 .res "); II
190
4.3. Windows
USEFORMCMainUnit.cpp", MainForm); II
WINAPIWinMain(HINSTANCE, HINSTANCE, LPSTR, int)
/* Widows*/
{try
II ,
{ Application-> Initialize ; II VCL
Application'>CreateForm(_ classid(TMainForm), &MainForm);
II
Application->RunO; II
}
return 0;
}
,
:
- , (
) -
C++ ( );
. - ,
(make-, );
.dfin - ( );
.h
- , ;
.hpp - , VCL.
Delphi
. :
.res - ;
.tds - .
1. MS DOS
32. , .
2. Win32?
.
3. : , , ,
. ,
Win32.
4. ?
Delphi C++Builder? ? ?
5. .
5. DELPHI PASCAL
Delphi Pascal , Borland
Pascal 7.., . 2
:
-
( , );
- (,
);
- ( , ,
RTTI);
- ( ) . .
5.1.
, Delphi (
),
TObject.
:
< > = 188(< >)
private
< >
protected
<1 >
public
< >
published < >
automated <, ->
end;
, , ,
, TObject.
.
1 private ,
( , C++),
.
protected ,
, , .
192
5.7.
^public ,
.
published ,
public. ,
, ,
, .
automated ,
public. , ,
, OLE.
TAutoObject.
, , private,
.
Delplii ,
, .. .
,
, , Delphi,
^ .
,
, - .
,
Pascal.
Borland Pascal 7.0:
Type pTNum = ^TNum;
TNum = Object
n: integer;
constructor Init (an: integer);
end;
Constructor TNum.Init;
begin
n: -an;
end;
. . .
Var p:pTNum;
Begin
New, Init(5));
WriteLn(p^.n);
Dispose(p)
Delphi:
Type
TNum = class
public n: integer;
constructor Create (an: integer);
end;
Constructor TNum.Create;
begin inherited Create;
n: =an;
end;
. . .
Var A: TNum;
. . .
A:=TNum.Create(5);
WriteLn(A.n);
A.Destroy . . . .
Delphi, :
Create () - Destroy () - .
,
193
5. Delphi Pascal
. ,
TObject,
.
Create TObject
InstanceSize ,
, ,
Newlnstance, ,
Initlnstanse. -
.
,
,
(inherited) :
Constructor TNum.Create;
begin
inherited Create; { }
n: =an;
end;
TObject,
.
.
,
, .
5.7.
TObject, ,
. 1
, :
Destructor TNum.Destroy;
begin
. . .
{ 1 }
inherited Destroys
{ }
end;
Delphi ,
Delphi ,
.
, ,
, . . 5.1 ,
.
5 . 1 . Delphi
1
VarA,B:TNum;
A:=TNuiiLCreate;
1 nil 1 1 nil 1
.
TNum.
.
,
X1
\
:=;
\ 1
\
1 B.Destroy;
f^1
1 \
A.Destroy;
B.Destroy;
A.I1
- 1
,
1 \
/-
- 1
. ,
, .
-
- 1
195
5. Delphi Pascal
. , .. nil.
.
.
,
. .
,
.
.
.
,
Destroy Free. , ,
, ( ,
, nil) , ,
. , , ,
. 5.1, Destroy Free
: ,
nil.
. ,
,
, - ,
.
5.1. (
- 1). ,
.
.
.
:
( ,
).
. 5.1.
^f
_. . >
^1
^ |
^|
^1
^
. 5.1.
196
5.7.
,
.
TForm
.
. 5.2.
,
1,
:
Forml:
Name:=MainForm;
11:=
""';
Bevell:
Name:= Bevel;
Imagel:
Name:=Image;
Labell:
Name:=rLabel;
:= ';
Editl:
Name:==rEdit;
Text:=";
UpDownl:
Name:=UpDown;
Associate :=rEdit;
Buttonl:
Name:=ColorButton;
Button2:
Name:=ExitButton;
BI-ID
/ ' ""
TLabel
Kpyi
TEdit
23
^TUpDown
^TButton
}^1!^1
/ r-
TMainForm
TBevel
TImage
TButton
. 5.2.
197
5. Delphi Pascal
.
.
(Name:=ColorDialog).
:
, , (
). , ,
Delphi, . 5.3.
1 (MainFormActivate)
.
2 (ImageMouseDown) ,
,
.
(CoIorButtonClick)
. ,
, ,
.
4 .
5 (UpDownClick) ,
, ,
.
6 (ExitButtonClick)
.
TMainForm,
TForm DelpM,
. 5.4, .
:
1 - ;
2 -
] Cf
4
|6
;
^
- ;
- ) 4 -
2
/ ;
6 - .
. 5.3.
198
5.1.
TMyCircle
TmainForm
111
|1
TMainForm
:
FormActivate
ImageMouseDown
UpDownClick
ColorButtonClick
ExitButtonClick
TMyCircle
:
Image: Timage
X, y, r: Word
Color: TColor
:
Create, Draw,
Clear, ReSize,
ReColor
. 5,4.
TMyCircle (. 5.4, ) Delphi
TObject.
(,), , Color Image,
.
,
(. . 5.2). Create,
. ,
Clear
.
:
Clear, , private
(), - public.
TMyCircle Circul:
Unit Circul;
Interface
Uses extctrIs,Graphics;
Type TMyCircle=class
private
X, y, r: Word; { }
Color: TColor; {}
Image: Timage; { }
Procedure Clear; { }
public
Constructor Create(almage:Timage; ax,ay,ar:Word;
aColor:TColor); {}
199
5. Delphi Pascal
Procedure Draw;
{}
Procedure ReSize(ar: Word); { }
Procedure ReColor(acolor: TColor); { }
end;
Implementation
Constructor TMyCircle,Create;
Begin inherited Create; { }
Image: =almage; { }
x:=ax; :-ay;
r:=ar; Color: =aColor;
End;
Procedure TMyCircle.Draw;
Begin
Image.Canvas.Pen.Color: =Color; { }
Image.Canvas.Ellipse(x-r, y-r, x+r, y+r); { }
End;
Procedure TMyCircle. Clear;
Var TempColor: TColor;
Begin
TempColor: =Color;
{ }
Color: =Image. Canvas.Brush. Color; { }
Draw;
{ - }
Color:=TempColor;
{ }
End;
Procedure TMyCircle.ReSize;
Begin Clear;
r:=ar; Draw; End;
Procedure TMyCircul.ReColor(aColor: TColor);
Begin Clear; Color: =aColor; Draw; End;
End
,
.
Main, TMainForm.
Unit Main;
Interface
Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls;
Type
TMainForm = class(TForm)
Bevel: TBevel;
{}
Image: TImage;
{ }
ColorButton, ExitButton: TButton; {}
rEdit: TEdit;
{ }
rLabel: TLabel;
{ }
200
5.7.
UpDown: TUpDown; { /}
ColorDialog: TColorDialog; { }
Procedure FormActivate{Sender: TObject);
Procedure ImageMouseDown{Sender: TObject; Button: TMouseButton;
Shift: TShiftState; AT, Y: Integer);
Procedure UpDownClick{Sender: TObject; Button: TUDBtnType);
Procedure ColorButtonClick(Sender: TObject);
Procedure ExitButtonClick(Sender: TObject);
end;
Var MainForm: TMainForm;
Implementation
{$R ''.DFM}
Uses Circul;
VarC'.TMyCircle;
Procedure TMainForm. FormActivate{Sender: TObject);
Begin Image 1. Canvas.Brush. Color: =clWhite; { }
Image I. Canvas.Pen. Color: =clBlack; { }
End;
Procedure TMainForm.ImageMouseDown{Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Begin
if Button=mbLeft then
{ }
begin
.Free;
{ , }
: -TMyCircle.Create(Imagel ,, Y,strtoint(rEdit. Text),
Image 1.Canvas.Pen.Color); {}
.Draw;
{ }
end;
End;
Procedure TMainForm. UpDownl Click (Sender: TObject;
Button: TUDBtnType);
Begin
ifConil then
{ , }
C.ReSize(strtoint(rEdit. Text)); { }
End;
Procedure TMainForm.ColorButtonClick(Sender: TObject);
Begin
ifColorDialog.Execute then { , }
ImageI.Canvas.Pen.Color: =ColorDialog. Color; { }
ifC< >nil then
{ , }
C.ReColor(Imagel.Canvas.Pen.Color); { }
End;
Procedure TMainForm.ExitButtonClick(Sender: TObject);
201
5. Delphi Pascal
{ , }
, TMyCircle
. ,
, .
, .
.
,
.
, ,
finalization.
5.2.
Delphi Pascal
. : ,
. ,
,
.
.
. ,
Delphi, ,
Borland Pascal 7.0.
,
.
.
.
virtual^ , ,
1 override. -
virtual,
, , virtual
.
.
.
,
. .
,
.
. Delphi
,
202
5.2.
, ().
, , dymamic - override .
,
, ,
(. 5.5).
, 1 ,
( - 5.6). ,
.
, .
,
,
, ,
.
(virtual).
.
, .
abstract
.
, ,
. ()
.
:
VI -virtual
V2 - virtual
Dl -dynamic
D2 - dynamic
:
VI -ovemde
Dl -oven-ide
A
TBM:
VI
V2
:
Dl
D2
:
VI
V2
:
D1
. 5.5.
203
5. Delphi Pascal
^ 1
'^
<
. 5.6.
5.2. (
- 1).
,
, , , .
. 5.6.
,
. TRadioGroup
(. 5.7).
2 (. .5.3)
.
TMainForm ,
, RadioGroup TRadioButton.
TMySquare .
" "
13
:!
]
'TRadioGroup
||
. 5.7.
204
5.2.
1. TMySquare TObject,
11.
, .
2. TMySquare TMyCircle (.5.8, ).
TMyCircle Create, Clear, ReColor, ReSize,
. Draw
,
-. Draw TMySquare
- override. ,
, (, ,
: ?).
3.
TFigure,
(. 5.8, ), Draw
(virtual) (abstract) Create,
Clear, ReColor, ReSize Draw.
, .
Draw TMyFigure.
Figxire
. 5.8, .
Unit Figure;
Interface
Uses extctrIs,Graphics;
Type TMyFigure=class
private
x,y,r:Word; Color: TColor;
Image :TImage;
procedure Clear;
public
Cons true tor Create (almage: TImage; ax, ay, ar: Word; aColor: TColor);
Procedure Draw; virtual; abstract; { }
leiil
TMyCircle
:
Image, , , Color
:
Create, ReColor,
Clear, ReSize,
Draw; virtual
TMySquare
: Draw, override
a
tlliBi
TMyFigure
TMyCircle
:
Image, x y, r, Color
:
Create, ReColor,
Clear, ReSize,
Draw; virtual; abstract
TMySquare
. 5.8.
205
5. Delphi Pascal
5.2.
. 4, Delphi Pascal
:
function DividefX, Y: Real): Real; overload; { 1}
begin
Result: = XJY; end;
function Divide(X, Y: Integer): Integer; overload; { 2}
begin
Result: = Xdiv Y; end;
,
:
k:=Divide(2.5, 7.3); { 1}
: =Divide(6,3);
{ 2}
,
. ,
, .
overload.
:
type
1 = class (TObject)
public
procedure Test(I: Integer); overload;
end;
T2 = class(Tl)
public
procedure Test(S: string); overload;
end;
Var SomeObject: T2;
SomeObject := T2.Create;
SomeObject.TestCHello!');
SomeObject. Test(7);
{ - Test
2}
{ - Test
1}
C++ Delphi
Pascal :
TSomeClass = class
207
5. Delphi Pascal
public
function Func(P: Integer): Integer;
function Func(P: Boolean): Integer { !}
,
.
,
, reintroduce.
:
1 = class (TObject)
public procedure Act I; virtual;
procedure Act2; virtual;
procedure Act3; virtual;
procedure Act4; virtual;
procedure Act5; virtual;
end;
T2 = class(Tl)
public
procedure Act 1;override; {
}
procedure Act2;virtual; { ,
}
procedure Act3;reintroduce;virtual; {
- ,
}
procedure Act4;
{ ,
, }
procedure Act5; reintroduce; {
- ,
}
end;
var SomeObjectl: Tl;
begin
SomeObjectl ;= T2.Create; {
}
SomeObjectl Act 1; { - 2}
SomeObjectl.Act2; { - 1}
208
5.2.
SomeObjectl.Act3; { - 1}
SomeObjectl.Act4; { - 1}
SomeObjectl .Act5; { - 1}
end;
, ,
, :
type
1 = class (TObject)
public
procedure Test(I: Integer); overload; virtual;
end;
T2 = class(Tl)
public
procedure Test(S: string); reintroduce; overload;
end;
, ,
,
( 4 Delphi):
procedure Confused(I: Integer); overload;
Begin... End;
procedure Confused (I: Integer; J: Integer = 0); overload;
Begin... End;
Confused(X); { ,
}
,
(
):
1 = class (TObject)
public
procedure Test(I: Integer); overload; virtual;
end;
T2 = class(TI)
public
procedureTest (I:Integer;S:string= 'aaa ) ; reintroduce; overload;
end;
209
5. Delphi Pascal
SomeObject ;= 2.Create;
SomeObject.Test(5,'Hello!');
SomeObject. Test(7);
{ -
Test 2}
{ - Test
2 }
, :
Tl=class
public
I: integer;
Constructor Create; overload;
end;
T2=class(Tl)
public
Constructor Create(aI:Integer);overload;
end;
Constructor Tl.Create;
Begin
inherited Create;
I: =10;
End;
Constructor T2.Create(aI: Integer);
Begin
inherited Create;
I:=al;
End;
Var SomeObject: T2;
SomeObject: =T2.Create; { - I
10}
SomeObject:=2. Create(5); { -
I 5}
5.3.
- Pascal Delphi,
.
Delphi :
;
-;
index;
.
210
5.3.
.
( ,
1 ):
property < >:<>
[read < >]
[write < >]
[stored < >]
[default <>];
, read write,
,
. ,
. ,
.
.
, ,
( ).
, ,
, published, ..
.
stored ( ,
) ,
(true - , false - )
.dfm. default
, .
:
private FValue: integer;
procedure SetValue(AValue: integer);
function StoreValue: boolean;
published
property Valuennteger read FValue write SetValue
stored StoreValue default 10;.. .
FValue
. .
SetValue.
, StoreValue true 10.
.
, ,
, , F,
. ,
Get, - Set.
211
5. Delphi Pascal
, / .
: - .
, :
. Value :=;
: =. Value;
:
A.SetValue(n);
k:=^AFValue;
:
- (, );
-
(,
).
5.3. (
- 2).
5.1.
,
.
Color Radius.
. . 5.9
TMyCircle .
:
Draw ,
. Circle :
TObject
TMyCircle
212
5.3.
Unit Circle;
Interface
Uses extctrls,Graphics;
Type TMyCircle^class
private x,yFRaditis:Word; FColor.TColor; Image:TImage;
Procedure Clear;
Procedure Draw;
Procedure SetSize(ARadius: Word);
Procedure SetColor(AColor:TColor);
public
Constructor Create(aImage:TImage;ax,ay,ARadii4s: Word;
AColor:TColor);
property Radius:Word write SetSize;
property Color: TColor write SetColor;
end;
Implementation
Constructor TMyCircle.Create;
Begin inherited Create;
Image :=almage; x:=ax;
y:=ay;
FRadius: =ARadius; FColor: =A Color;
Draw;
End;
Procedure TMyCircle. Draw;
Begin Image. Canvas. Pen. Color: =FColor;
Image.Canvas.Ellipse(X'FRadius, y-FRadius,
x+FRadius, y+FRadius);
End;
Procedure TMyCircle.Clear;
Var TempColor: TColor;
Begin TempColor: =FColor;
FColor: =Image. Canvas.Brush. Color;
Draw;
FColor: "^TempColor;
End;
Procedure TMyCircle.SetSize;
Begin Clear;
FRadius:=ARadius; Draw;
end;
Procedure TMyCircle.SetColor;
Begin
Clear; FColor:-AColor;
Draw;
end;
End.
:
213
5. Delphi Pascal
e a H e.
Delphi. , , Visible,
,
.
,
,
( public), ..
.
-. -
( ,
):
property <> < >:<>
[read < >] [write < >] [default];
.
- .
. ,
,
.
!, .
, ,
. -
.
default ,
(
).
:
private function GetValMas(I:word;F:double):word;
procedure SetValMas(I:word;F:double;AElement:word);
public prorerty ValMasfLword, F:double]:word
read GetValMas write SetValMas; default;
,
-,
214
5.3.
.
,
, :
MyObject[k-^2,s] :=/;
MyObject. ValMas[k+2,s]:=l;
-
, , ,
( ,
).
5.4. - (
- 1).
-.
.
.
:
- TSringGrid ;
- ;
- ;
- .
,
.
Unit MasByte;
Interface
Uses SysUtils, Dialogs, Grids;
Type
TMas=array[1..255] of byte;
TMasByte = class(TObject) { }
private
ptr_an: ^TMas; { }
len.'byte;
{ }
Procedure SetEl(Ind:byte;m:byte); { }
Function GetEl(Ind:byte):byte;
{ }
public
n.'Byte;
{ }
Constructor Create (an: byte);
Destructor Destroy; override;
215
5. Delphi Pascal
5.3.
5. Delphi Pascal
Function TMasByte.Delete;
Var i: integer;
Begin
Result: =Mas[Ind];
for i: =Ind+l to n do Mas[i'l]: =Mas[i];
End;
End,
n:-n-l;
:
: =TMasByte. Create(k);
, 1:
[6]-7;
, -
,
.
( index).
:
property <> : <> index <>
read < > write < >;
<> - Shortlnt.
, /.
/ ,
.
, - ,
, .
- ,
. , ,
:
CMasF^class
private
FMasEl:array[l:3] of word;
{-}
function GetElfInd:byte).word;
{ }
procedure SetEl(Ind:byte;AElement); { }
public
218
5.4.
5. Delphi Pascal
is. ,
:
<> is <>
true, , false -
.
as. ,
(. . 1.25) :
<> as <>
,
, as
,
.
. Delphi ,
.
Self
.
class:
MyClass=class(TObject)
public
class procedure < >(< >);
end;
( )
, .
, , TObject,
,
(. ).
.
Delphi .
DelpM Pascal ,
. ( Run Time Type Information - )
.
, (
, , , , , ,
220
5.4.
).
, , ~ ,
, , - (
), . RTTI
DelpM
,
.
.
Typelnfo, .
lypelnfo Pointer RTTI .
TTypelnfo, lyplnfo,
.
^^ GetiypeData,
TTypeData, .
RTTI .
RTTI ,
.
, .
.
()
1
[
\
\
zr^
[
\
RTTI
DefaultHandler
Newlnstance
Freelnstance
Pestroy
*:^
RTTI
. 5.10.
221
5. Delphi Pascal
(. 5.10),
.
, , .
Delphi ,
, ,
. . 5.2
Delphi 3.
5.2.
1
-64
-60
-56
-52
-48
-44
-40
-36
-32
-28
-24
-20
1
-16
-12
-8
-4
0
T13M
OLE
,
( Cardinal)
-
SafecallException
DefaultHandler
Newlnstance
Freelnstance
Destroy
1
1
1
1
1
1
1
1
1
1
1
|
, ,
, :
ShortString(Pointer(Pointer(Integer(TEdit) - 32)'')'').
TObject ,
:
1) class function ClassName: ShortString; - ;
2) class function ClassNameb(const Name: string): Boolean; -
true, ;
3) class function ClassParent: TClass; -
;
4) class function Classlnfo: Pointer; -
RTTI ;
5) class function InstanceSize: Longint; -
;
222
5.4.
6) class function InheritsFrom(AClass: TClass): Boolean; - ,
;
7) class function MetliodAddress(const Name: ShortString): Pointer; ;
8) class function MetliodName(Address: Pointer): ShortString; .
,
.
,
.
.
5.5. .
R i l l ,
,
, .
: TSpisok
TElement. TSpisok TElement,
sue pre,
.
. 5.11.
Spisok, TElement TSpisok,
:
Unit Spisok;
Interface
Type TElement=^class(TObject)
public
pre,suc: TElement;
end;
TObject
TElement
:
sue, pre: TElement
^>^
TSpisok
5. Delphi Pascal
TSpisok-class{TObjecf)
private first, last, cur: TElement;
public
Destructor Destroy; override;
Procedure Add(e: TElement); {}
Function Del: TElement;
{}
Function IFirst: TElement; { }
Function INext: TElement;
{ }
end;
Implementation
Destructor TSpisokDestroy;
Varv: TElement;
Begin
v:=Del;
while v<>nil do begin v.Destroy; v:=Del; end;
inherited Destroy;
End;
Procedure TSpisokAdd;
Begin
if first-nil then beginfirst:=e; last:=e; end
else begin e.suc: -first; first,pre: -e; first: =e; end;
End;
Function TSpisokDel;
Begin Del: =last;
iflastonilthen
begin last:=last.pre; iflast<>nilthenlast.suc:=nil; end;
iflast=nil then first: =nil;
End;
Function TSpisokJFirst;
Begin
cur:-first;
Result: ^cur; End;
Function TSpisokJNext;
Begin
cur:=cur.suc; Result:-cur; End;
End
,
( TMyNumber, TMyString
TMySpisok, ). . 5.12.
MySpisok:
Unit MySpisok;
Interface
Uses Spisok;
Type TMyNumber=class(TElement)
private
FMyNum: integer;
224
5.4.
: MyNum
: MyStr
: Summa
. 5.12. TSpisok
public
end;
TMyString=class{TElement)
private
FMyStr: string;
public
Constructor Create(aMyStr:string);
property MyStr:string read FMyStr Write FMyStr;
end;
TMySpisok=class{TSpisok)
public Function Summa: integer;
end;
Implementation
Constructor TMyNumber Create;
Begin
inherited Create;
FMyNum: ^aMyNum;
End;
Constructor TMyString Create;
Begin
inherited Create;
FMyStr: =aMyStr; End;
Function TMySpisok. Summa;
Var c:TElement;
Begin Result: =0; c: =IFirst; { }
while cOnil do
{ }
begin
if is TMyNumber then { - -, }
Result: =Result+{c as TMyNumber).MyNum; {,
MyNmn - , }
: =INext;
{ }
end;
End;
End
225
5. Delphi Pascal
HI-IQ
.
/
tyuiuyt
. 5.13.
, ,
, .
.
,
TElement. , ,
, .
. 5.13.
.
.
Unit Main;
Interface
Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dia
logs, StdCtrls;
Type
TMainForm = class{TForm)
AddButton, DelButton, SumButton, ExitButton: TButton;
lOEdit: TEdit; lOLabel, ListLabel: TLabel;
ListBoxl: TListBox;
Procedure ExitButtonClick(Sender: TObject);
226
5.4.
5. Delphi Pascal
5.5.
Type TMyClass=class
private FMetod.TMyMetod;
public property Me tod: TMyMetod read FMetod write FMetod;
end;
5.4,
. DelpM
( 1.7), /?:/
.
,
.
^
.
5.6. (
- 2).
,
. 5.2,
. TCircle TSquare
Draw.
.
.
,
(. 5.14).
*'
;.
0|
||
. 5.14.
229
5. Delphi Pascal
1.
, TFigure
DrawCircle ( ) DrawSquare ( ),
Draw -
.
TDProc.
unit Figure;
interface
Uses extctrls,Graphics;
Type TDProc='procedure of object;
TMyFigure=class
private
x,yr:word;
Image :TImage;
FDraw:TDProc; { Draw}
public
Constructor Create(aImage:TImage;ax,ay,ar:Word); {}
property Draw:TDProc read FDraw write FDraw; {
}
Procedure Clear;
{ }
Procedure DrawCircle;
{ }
Procedure DrawSquare;
{ }
end;
Implementation
Constructor TMyFigure. Create;
Begin
inherited Create; Image: =almage;
x:=ax; y:'=ay; r:=ar;
End;
Procedure TMyFigure.Clear;
Begin Image. Canvas.Pen. Color: =clWhite;
Draw; { , }
Image. Canvas.Pen. Color: =clBlack;
End;
Procedure TMyFigure. DrawCircul;
Begin Image.Canvas.Ellipse(x-r,y'r,x+r,y^r); End;
Procedure TMyFigure.DrawSquare;
Begin Image.Canvas.Rectangle(X'r,y'r,x+r,y+r); End;
end.
:
case RadioGroup.Itemlndex of
230
5.5.
0: C.Draw:^C,DrawCircle;
1: C.Draw:=C.DrawSquare;
end;
Draw ( )
RadioGroupClick (
):
Procedure TMainForm.RadioGroupClick(Sender: TObject);
Begin ifConil then
{ , }
begin
. Clear;
{ }
case RadioGroup.Itemlndex of { }
0: C.Draw:=C.DrawCircle; { }
1: C.Draw:=C.DrawSquare; { }
end;
C.Draw;
{ }
end;
End;
2. - ^
, .
TDraw,
.
, .
Unit Figure;
Interface
Uses extctrls,Graphics;
Type TParam-record
x,yfr:Word;
Color: TColor;
Image: TImage;
end;
TDProc=Procedure(AParam:TParam) of object;
TMyFigure=class
private
FDraw.TDProc;
public
Param:TParam;
Procedure Clear;
Constructor Create(aImage:TImage;ax,ay,ar:Word;aColor:TColor);
property Draw:TDProc read FDraw write FDraw;
end;
TDraw=^lass
231
5. Delphi Pascal
public
Procedure DrawCircle{AParam:TParam);
Procedure DrawSquare{AParam:TParam);
end;
Implementation
Constructor TMyFigure.Create;
begin
inherited Create;
Param. Image: =almage; Param. Color: =aColor;
Param.x: -ax; Param.y: =ay; Param. r: =ar;
end;
Procedure TMyFigure.Clear;
Var TempColor:TColor;
Begin
TempColor: =Param.Color;
Param. Color: =Param. Image. Canvas. Brush. Color;
Draw(Param);
{ }
Param. Color: -TempColor;
End;
Procedure TDraw.DrawCircle;
Begin
AParam.Image. Canvas.Pen. Color: =AParam. Color;
AParam.Image.Canvas.Ellipse(AParam.X'AParam.r,AParam.y'AParam.r,
AParam.x+AParam. r,AParam.y+AParam. r);
End;
Procedure TDraw.DrawSquare;
Begin
AParam.Image. Canvas.Pen. Color: =AParam. Color;
AParam.Image. Canvas.Rectangle(AParam.x-AParam. r,
AParam.y-AParam.r, AParam.x-^AParam.r, AParam.y+AParam.r);
End;
End.
Draw
RadioGroupClick :
Procedure TMainForm.RadioGroupClick(Sender: TObject);
Begin
ifConilthen
begin
CClear;
case RadioGroup.Itemlndex of
0: C.Draw:=G.DrawCircle; { }
I: C.Draw:=G.DrawSquare; { }
end;
232
5.6. Delphi
C.Draw{C.Param);
{ }
end;
End;
G TDraw
- :
initialization G: =TDraw.Create;
flnalization G.Free;
5.6. Delphi
Delphi VCL ,
Windows.
. 5.15
VCL, Delphi.
,
TObject, ,
Delphi:
type
TObject = class
constructor Create;
{}
destructor Destroy; virtual; {}
TObject
TPersistent
TCanvas
TMenu
TComponent
TScreen
TControl
TStrings
I
TApplication TCommonDialog
I
TGraphicColor
TWinControl
TOpenDialog
TSaveDialog
TLabel
TEdit
TButton
TCustomForai
X
TForm
. 5.15. VCL
233
5. Delphi Pascal
procedure Free;
{, }
class Function Initlnstance(lnstance: Pointer): TObject; {
}
class Function Newlnstance: TObject; virtual; {
}
Procedure Cleanuplnstance; {
}
Procedure Freelnstance; virtual; { ,
}
Function ClassType: /^; { }
class Function ClassName: ShortString; { }
class Function ClassNamels(const Name: string): Boolean; {
}
class Function ClassParent: TClass; { }
class Function Classlnfo: ^; {
RTTI}
class Function InstanceSize: Longint; {
}
class Function InheritsFrom(AClass: TClass): Boolean; {
}
Procedure Dispatch(var Message); { }
class Function MethodAddress(const Name: ShortString): Pointer;
{ }
class Function MethodName(Address: Pointer): ShortString;
{ }
Function FieldAddress(const Name: ShortString): Pointer;
{ }
Function Getlnterface (const IID: TGUID; out Obj): Boolean; {
}
class Function GetInterfaceEntry(const IID: TGUID):
PInterfaceEntry;
{ ,
}
class Function GetlnterfaceTable: PInterfaceTable; {
,
}
Function SafeCallException(ExceptObject: TObject;
ExceptAddr: Pointer): Integer; virtual;
{ OLE}
Procedure DefaultHandler(var Message); virtual; {
}
end;
234
5.6. Delphi
TObject ,
published - TPersistent.
( ,
).
TPersistent TComponent () -
, : TStrings (), TCoUection (), TCanvas
( ~ , ), TGrapMcObject (
), TGraphic ( ), TPicture ().
TComponent ,
( TApplication).
TComponent , -
- .
:
. ,
(TForm), ,
(TApplication).
-
TComponent :
1) Owner -
(
);
2) Componentlndex -
Components ( 0) ;
;
3) Components[Index] - - TComponent,
;
4) ComponentCoimt -
.
, -
Components ComponentCount
.
TComponent TControl,
, .
, ,
.
,
.
.
TControl ,
235
5. Delphi Pascal
(,
, ..).
TControl TMnControl -
TGrapMcControl - .
, , Windows (TEdit,
TMemo, TListBox), , ..
. , TWinControl
, .
TGraphicControl (TLabel, TImage,
TBevel). .
TWinControl
- .
.
, ,
(, ..).
(, ..).
- -
. ,
.
, ,
(. 5. 16).
,
text TStrings:
TMainForm = class{TForm)
GroupBox: TGroupBox; Checkbox 1: TCheckBox;
TForm^.,.^^
1 .
[^ :
TGroupBox.
TCheckBox
01
]Z:
feTButton
^
.^
TOpenDialog TSaveDialog
. 5.16. ( )
236
5.6. Delphi
MainFomi
1
GroupBox CheckBox2
5. Delphi Pascal
4) ControlCount -
.
:
1) ParentCoIor: boolean - ,
;
2) ParentFont: boolean - ,
;
3) ParentShowHint:boolean - ,
ShowHint .
, ,
:
1) SetFocus -
;
2) FindNextControl - ,
TabOrder;
3) Enabled - ,
;
4) TabOrder -
Tab;
5) ActiveControl -
, .
- ,
.
5.7. -
( ).
,
.
8 TEdit (. 5.19).
TEdit ,
Tab, ,
Enter. Tab
Enter, TEdit
KeyPress.
TEdit. ,
.
, ,
, ,
- . ,
238
5,6. Delphi
Igy
:
X
: 0
-6h
5.1
1XI
V J J ICi-lVrutXil^llri
jojr"j|
. 5.19.
TMainForm ( FormActivate -
), Enter (
AUEditKeyPress - Enter TEdit) 8
TEdit ( ExButtonCIick - ,
).
TMainForm = class(TForm)
Bevel1: TBevel; InputLabel: TLabel;
ALabel: TLabel; BLabel: TLabel;
CLabel: TLabel; DLabel: TLabel;
AxEdit: TEdit; AyEdit: TEdit;
BxEdit: TEdit; ByEdit: TEdit;
CxEdit: TEdit; CyEdit: TEdit;
DxEdit: TEdit; DyEdit: TEdit;
NextButton: TButton; ExitButton: TButton;ExButton: TButton;
ResLabel: TLabel; ResultLabel: TLabel;
xlLabel: TLabel; 1 Label: TLabel;
x2Label: TLabel; y2Label: TLabel;
procedure AUEditKeyPress (Sender: TObject; var Key: Char);
procedure FormActivate (Sender: TObject);
procedure ExButtonClick(Sender: TObject);
procedure NextButtonClick(Sender: TObject);
procedure ExitButtonClick(Sender: TObject);
end;
239
5. Delphi Pascal
Implementation
Var K:array[l..S\ of Double;
Procedure TMainForm.FormActivate(Sender: TObject);
Var i: integer;
Begin
for i: =0 to ControlCount'l do
{
}
ifControls[i\ is TEdit then
{ - TEdit, }
begin
Controls[i\.Enabled: = true;
{ }
(Controls[i] as TEdit).ReadOnly:=false; { }
end;
ExButton. Visible: =true;
{ }
NextButton.Enabled: =false; {
}
ResLabel Visible: =false;
{ }
ResultLabel. Visible: =false; { }
AxEdit.SetFocus; { TEdit (TabOrder=0)}
End;
Procedure TMainForm.AllEditKeyPress{Sender: TObject; var Key: Char);
Var Code: integer; S:string;
Begin
ifKey-#13 then
{ Enter, }
begin
Key: =#0;
{ - }
Val{{ActiveControl as Tedit). Text,
K[{ActiveControlas Tedit).TaglCode);
{
Tag }
ifCodeoO then { , }
begin
{ }
S: =chr(ordCA') +ActiveControL TabOrder div 2);
MessageDlgC '+*$'+
' .',mtError,[mbOk], 0);
exit;
end;
FindNextControl{ActiveControlytruefalsefalse).SetFocus; {
}
end
End;
Procedure TMainForm.ExButtonClick(Sender: TObject);
Var CodeJJ:integer; PP:TEdit; S:string; . . .
240
5.7.
Begin
: =AxEdit;
{ (TabOrder = 0)}
for i: =1 to 8 do
{ 8 }
begin
Val(PPText, K[PPTag\Code); { }
ifCodeoO then
{ , }
begin
{ }
S: =chr(ordCA')-^PP TabOrder div 2);
PPSetFocus;
MessageDlgCKoopdunambi '-^S^' .',
mtErroK [mbOk], 0);
exit;
end;
ifi<>8 then PP:=FindNextControl(PP,truefalse,true) as TEdit; {
}
end;
{ ,
}
PP:=AxEdit;
for i:=l to 8 do
begin
PP. Enabled: =false;
PPReadOnly:=true;
ifi<>8 then PP:=FindNextControl(PP,truefalse,true) as TEdit;
end;
End;
. .
Tag.
TComponent 32 .
, .
5.7.
1 VCL
.
.
:
1) ;
241
5. Delphi Pascal
2) ( ) ;
3) ,
;
4) () .
Delphi. Delphi 100
. Windows
. Msg.
- 16- ( Cardinal).
, .
.
.
, , Delphi,
:
TMessage-record
Msg: Cardinal;
case Integer of
0: (WParam.'LongInt; LParam.Longlnt; Result:Longint);
1: {WParamLo:Word; WParamHi:Word;
LParamLo: Word; LParamHi: Word;
ResultLo.Word; ResultHLWord);
end;
end;
. ( )
: ,
( ,
..).
,
$399 .
WMUSER=$400,
:
Const Mesl = WMJJSER;
Mes2 = WMJJSER+1;
. ,
,
1 .
^ , Delplii.
,
1 dinamic override :
Procedure wm< >( Message: < >);
message < >;
242
5.7.
,
, :
,
1 message.
,
.
,
:
type < >= class < ->
public
Procedure wm< >( Message:<THn >);
message < >;
end;
-,
,
.
( ,
):
procedure < >. wm< >;
begin
< >
inherited;
end;
,
, ,
.
, DefanltHandler TObject,
.
. Delphi
.
1.
:
function SendMessage (liWnd:Integer, Mes:Cardinal;
WParam, LParam:LongInt):LongInt;
. hWnd
, - -
243
5. Delphi Pascal
Windows ( ).
Handle, TWinControL
2.
:
function PostMessage(hWnd:Integer,Mes:Cardinal;
WParam,Param:LongInt):LongBool;
SendMessage,
SendMessage PostMessage
, .
True, , False -
.
3.
,
TControl:
procedure Perform (Mes:Cardinal; WParam, LParam:LongInt);
, ,
, .
5.8. / . ,
. .
5.20 .
, ,
, . ~
1
.
, Unitl
, . TForail
SendButton:
J^' .
:
| | ! ^
fi^
BOLXJ
. 5.20. /
244
5.7.
Unit Unit 1;
Interface
Type MyMessage=Record
Msg:Cardinal;
{ }
PString:PChar; { }
Result:LongInt;
{ }
End;
Const WM_MYMESSAGE=WM_USER; {
}
TForml = class(TForm)
public SecondHandle:Integer;
{
}
end;
Implementation
Procedure TForml, SendButtonClick(Sender: TObject);
Begin
SendMessage(SecondHandle, WM_MYMESSAGE,
Longint(MessageEditText),0);{TQKQpaii^R }
End;
. . .
.
, TForm2
. ,
:
Unit Unit2;
Interface
Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dia
logs, StdCtrls, Unitl{ };
Type TForm2 = class (TForm)
MessageEdit: TEdit;
procedure FormCreate(Sender: TObject);
public
Procedure WMMyMessage(var Msg:MyMessage);
MESSAGE WM_MYMESSAGE;{ }
end;
Var Form2: TForm2;
Implementation
{$R *DFM}
Procedure TForm2. FormCreate (Sender: TObject);
Begin
245
5. Delphi Pascal
Forml.SecondHandle:=Handle; {
}
End;
Procedure TForm2. WMMyMessage(var Msg:MyMessage);
Begin
MessageEdit. Text: =Msg.PString;
( }
End;
End.
PostMessage:
PostMessage(SecondHandle, WM_MYMESSAGE,
Longint(MessageEdit. Text), 0);
Perform,
1) Unitl
Unit2:
Uses Unit2;
2) Form2:
Form2.Perform (WM_MYMESSAGE,Longint(MessageEdit. Text\0);
TForml .
. ,
,
.
,
. , ,
. Delphi ,
On: OnClick, OnCreate ..
function Assigned(var ): Boolean;
, -
. True, , False -
.
5.9. .
, . 11
.
Unit2 TPCharEvent,
: Sender - 246
5.7.
MyString - ,
. OnPChar PCharProc. -
FormCreate.
Unit Unit2;
Interface
Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dia
logs, StdCtrls, Unitl;
TypeTPCharEvent=procedure(Sender: TObject;MyString:PChar) of
object; TForm2 = class (TForm)
MessageEdit: TEdit;
procedure FormCreate (Sender: TObject);
private
FOnPChar:TPCharEvent;
{ }
public
property OnPChar: TPCharEvent read FOnMessage
write FOnMessage; {- OnPChar }
Procedure PCharProc(Sender: TObject; MyString:PChar);
{ OnPChar}
Procedure WMMyMessage(var Msg.MyMessage);
MESSAGE WM_MYMESSAGE;
end;
Var Form!: TForml;
Implementation
{$R *DFM}
Procedure TForm2. FormCreate (Sender: TObject);
Begin
Forml .SecondHandle: =Handle;
OnPChar:- PCharProc; { }
End;
Procedure TForm2. WMMyMessage(var Msg:MyMessage);
Begin
ifAssigned(OnPChar) then { , }
OnPChar (Self Msg.PString);
{ }
End;
Procedure TForm2.PCharProc(Sender: TObject;MyString:PChar);
Begin MessageEdit.Text:=MyString; End;
End.
VCL. VCL Delphi
. ,
.
247
5. Delphi Pascal
, W M K e y D o u n ,
TEdit, ,
(. 5.21).
WMKeyDoun .
, CnKeyDoun
.
CmKeyDoun ,
, .
(.. ),
, .
,
WMKeyDoun ,
.
.
Delphi Run TApplication.
. ,
HandleMessage,
.
, ..,
1
Cn_KeyDoun^[
Cm ChildKe
WMKeyDoum
^ |WM_KeyDoim^[ [
LWM_KeyDoun
Cn_KeyDoun
WM_KeyDoun
Cm_ChildKey
Cm_ChildKey
. 5.21.
248
5.7.
WMQUIT.
WMQUIT Terminated True
:
... repeat HandleMessage
until Terminated;...
,
.
,
. ,
, , ,
,
.
TProgressBar .
, - .
,
ProcessMessages TAplication.
,
.
, W M Q U I T
(, )
. ,
ProcessMessages
, , Termiinated,
.
5.10. .
, .
TProgressBar, ,
.
(. 5.22).
>*' .
-
^07201
.
TForml Cancel,
True
.
. 5.22.
.
249
5. Delphi Pascal
Unit Unitl;
Interface
Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls;
Type
TForml = class(TForm)
StartButton: TButton; ExitButton: TButton;
procedure StartButtonClick(Sender: TObject);
procedure ExitButtonClick(Sender: TObject);
procedure ButtonClick(Sender: TObject);
private Cancel: Boolean;
end;
Var Forml: TForml;
Implementation
{$R *DFM}
Procedure TForml.StartButtonClick(Sender: TObject);
Var iJ'.integer;
ProgressBar: TProgressBar; Button: TButton;
Begin
ProgressBar ;= TProgressBar.Create(Self); {
TProgressBar, Forml}
Button:=TButton.Create(Self); { -,
Form 1}
ProgressBarParent: = Self; { Forml }
ProgressBar.Left: =30; ProgressBar Top: =45; {
}
Button. Parent: =Self;
{ FormlcTapniHM}
Button. Caption:=^';
{ }
Button.Left: =60; Button. Top: =65;
{
}
Button.OnClick:=ButtonClick;
{
}
forj:=0to9do
begin
for i:=l to 10000 do
begin
Canvas. TextOut{90,20,IntToStr(i))\
Application.ProcessMessages;
{ ,
}
if Cancel then break;
{ Cancel,
}
end;
250
5.8.
ProgressBar.StepIt; { ProgressBar
}
if Cancel then break; { Cancel,
}
end;
ProgressBar.Free; { TProgressBar}
Button.Free;
{ TButton}
Canvas. TextOut(70,20, ' ');
end;
Procedure TForml.ButtonCUck; { }
Begin Cancel:=true; End; { Cancel}
Procedure TForml.ExitButtonClick(Sender: TObject);
Begin Close; End;
End.
5.8.
,
:
, ,
..
,
.
.
, .
.
Delphi
,
, ,
,
.
.
.
, Exception.
,
:
251
5. Delphi Pascal
if then :=/
else <
>
try :=/;
except
on EDivByZero do
< >
end;
, ,
,
. , ,
.
,
,
.
,
.
:
-
,
- , 1;
- ;
~ .
. ,
,
try ...finally try ... except, <
:
try <, >
finally <,
>
end;
try <, >
except <,
>
end;
.
,
, -
, . ,
252
5.8.
.
,
,
.
.
.
Exception.
, .
Exception - .
DelpM 4 :
Exception = class{TObjeci)
private
FMessage: string;
FHelpContext: Integer;
public
Constructor Create{const Msg: string); { ,
}
Constructor CreateFmt(const Msg: string;
const Args: array of const); { ,
, }
Constructor CreateRes{Ident: Integer; Dummy: Extended = 0); {
, }
Constructor CreateResFmt^Ident: Integer;
const Args: array of const); { ,
,
}
Constructor CreateHelp{const Msg: string; AHelpContext: Integer); {
}
Constructor CreateFmtHelp{const Msg: string;
const Args: array of const; AHelpContext: Integer); {
}
Constructor CreateResHelp{Ident: Integer; AHelpContext: Integer); {
, , }
Constructor CreateResFmtHelp(Jdent: Integer;
const Args: array of const; AHelpContext: Integer); {
,
, }
property HelpContext: Integer
read FHelpContext write FHelpContext; { }
property Message: string read FMessage write FMessage; { }
end;
253
5. Delphi Pascal
:
(. ).
Exception , ,
:
EDivByZero = class{EIntError); { }
ERangeError = class(EIntError); {
}
EIntOverflow = class{EIntError); { }
EMathError = class(EExtemaf); { }
EInvalidOp = class(EMathError); { )
EZeroDivide = class{EMathError); {
}
EOverflow = class{EMathError); {
}
EUnderflow = class{EMathError); {
}
, . ,
, , .
.
(
) ( ).
raise,
-,
:
ifn=0 then raise EDivByZero. Create{ ' 0.');
EDivByZero.
,
.
.
.
except try ... except )
case:
except
on < > do <>;
on < > do <>;
on < > do <>;
254
5.8.
else <>
end;
,
.
,
-.
1- . ,
- .
on
:
try . , .
except
on E:EDivByZero do { }
begin
<
, , E.Message>
end;
else < - >
end;
2- .
function xceptionObject:TObject;
,
nil:
try < >
except
on EDivByZero do
ShowMessage(EDivByZero(ExceptionObject).Message); {
}
end;
try ... except,
except ,
except raise:
try , . ,
try
...
except
on < > do <>;
255
5. Delphi Pascal
else raise;
end
except
< >
end;
, ,
1 .
var ErrorAddr: Pointer
raise ... at..., :
raise Exception.Create(' ') atErrorAddr;
5.11. (
- 2).
,
5.4.
,
.
. .
,
:
1) ;
2) ()
,
;
3) ,
.
: SetEl,
GetEI InputMas.
,
:
Unit MasByte;
Interface
Uuses SysUtils, Dialogs, Grids;
Type
256
5,8.
TMas=array[L,255] of byte;
TMasByte = class (TObjeat)
private
ptran: ^TMas; { }
len.'byte;
{ }
Name:string; { }
Procedure SetEl(Ind: byte;m: byte);
Function GetEl(Ind:byte):byte;
public
n:Byte;
{ }
Constructor Create (an: byte ;aName: string);
Destructor Destroy; override;
Property Mas[Ind: byte]:byte read GetEl write SetEl;default;
Procedure Modify(Ind: byte; Value: byte);
Procedure Insert(Ind:byte; Value: byte);
Function Delete (Ind: byte): byte;
Function InputMas (Grid: TStringGrid;I,J: integer): boolean;
Procedure OutputMas(Grid: TStringGrid;IJ:integer);
end;
EInputError=class(Exception); { }
Implementation
Constructor TMasByte.Create;
Begin
inherited Create;
GetMem(ptrjan, an);
len: =an;
Name:-aName;
End;
Destructor TMasByte.Destroy;
Begin
FreeMem(ptrjm);
inherited Destroy;
End;
Procedure TMasByte. SetEl (Ind: byte;m: byte);
Begin
iflnd<=len then
iflnd<=n
thenptrjm^{Ind\:-m
else
raise ERangeError.CreateFmt( 'B %s -
. \ [Namejnd\)
{ }
else
raise ERangeError.CreateFmt( 'B %s:
%d / ,[Name,Len]); { }
End;
257
5. Delphi Pascal
5.8,
,
. ,
:
A:=TMasByte.Create(10/A%' { }
try AJnputMasfStringGrid, 0,0); { }
except
on E:EInputError do { }
MessageDlg{E.Message,mtInformation, [mbOk] ,0);
end;
, -
:
try A[Ind\: = Value; { }
except
on E:ERangeError do {
)
MessageDlg(E.Message,mtInformation, [mbOk], 0);
end;
1. , Delphi Pascal.
Pascal 7.0?
, ++3.1?
2. ?
? ,
. .
3. .
? .
4. ? ?
, .
?
5. <^ .
, ?
6. VCL? /
/? ?
7. Delphi?
? ?
?
8. ?
? /
. , .
6. C++ BUILDER
C++ Builder
C++, 3. ,
, C++, ..
, .
, C++ Builder VCL,
Delphi Delphi Pascal. ,
C++ Builder C++ Pascal Delphi,
,
, Delphi Pascal, C++.
C++ :
-
, OLE-;
- ;
- ,
Delphi Pascal (, ..);
- ( closure);
- ( declspec), ,
, Delphi Pascal.
C++ Delphi Pascal
, .
C+-+Builder :
C++ VCL- -
VCL.
6.1. ++
, C++ Builder
( Borland C++ 3.1) . :
- ;
~ ;
- ;
- .
. -
.
260
6.7. C+ +
, .
C++
,
.
:
namespase [<>] { < > }
,
.
.
, ,
, .
1 $$$.
, ,
,
. ,
.
:
namespace ALPHA {
II ALPHA -
long double LD;
II
float/(float ) { return ;} II
;
, .
, ,
, ,
,
(, ..).
:
- ,
:
ALPHA:: LD
ALPHA::fO
- using, ,
:
namespace BETA {
using ALPHA::LD; I* ALPHA::LD BETA*/;
261
6. C++ Builder
- using,
:
namespace BETA Z'
...
using ALPHA; /* ALPHA BETA*/ }
-- ,
.
< >::.
using .
using .
6.1.
( using).
-+ - Object.h:
mjhdefObjectH
Mefine ObjectH
class A
{ public: voidfunc(char ch, TEdit ^^Edit);
};
class : public A
{ public:
voidfunc(char *str,TEdit *Edit);
using Ar.func;
II ::func
};
#endif
Object.cpp:
include <vcl.h>
^pragma hdrstop
mnclude " Object.h"
void A: :func(char ch, TEdit *Edit)
II
{ Edit'>Text=AnsiStringCcuMeon");}
void B::func(char *str, TEdit *Edit)
II
{ Edit'>Text=AnsiStringC");}
#pragma package (smart Jnit)
, ,
:
262
6.1. C+ +
;
b.funcCc\Edit); // A::func(), -
b.func("c'\Edit); // BiiftmcQ, -
. . C++
.
, .
< >::.
,
.
, base:
class base
{ public: voidfunc(int x, TEdit *Edit);
}:
TO
, :
base ;
void (base::*bptr)(int,TEdit *); II
bptr = & base::func;
II
(. *bptr)(],ResultEdit);
II
,
( ):
class derived: public base
{ public: void newjiinc(int i, TEdit *Edit);
}:
bptr =&derived::newjunc; II !!!
closure C++ Builder
- .
, .
,
.
:
<> (
, , ^
:
263
6. + + Builder
base ;
derived ;
void _ ^closure *bptr)(int, TEdit *); II
bptr = &A.func;
/*
*/
bptr(l,ResultEdit);
II
bptr = &.newJune; /*
*/
bptr(l,ResuItEdit);
II
. ,
,
, ,
.
:
class base
{ public: virtual voidfunc_poly(TEdit *Edit);
};
class derived: public base
{ public: virtual voidfunc_poly(TEdit *Edit);
}:
base *pB;
pB=new derived;
void ( closure *bptr) (TEdit *); II
bptr = &pB->func_poly; /*
,
*/
bptr(ResultEdit);
II
, .
6.2. (
).
,
5.5 ( 5.6). TFigure
Object.h:
#ijhdef FigureH
Mefine FigureH
typedefvoid ( closure *type_pMetod)(TImage *);
class TFigure
(private: intx,yr;
264
6.1. C+ +
type_pMetod/Draw;
public:
property type_pMetodDraw -{read-fDraWyy^rite-fDraw};
TFigure(int, int, int, TImage * TRadioGroup *);
void DrawCircle(TImage *);
void DrawSquare(TImage *);
void Clear (TImage *);
};
#endif
Object.cpp:
Mnclude <vcLh>
#pragma hdrstop
^include 'Figure.h"
TFigure::TFigure(intX, int Y, int R,
TImage *Image, TRadioGroup *RadioGroup)
{x=X;
y=Y; r^R;
switch (RadioGroup'>ItemIndex) II
{case 0: Draw=DrawCircle; break;
easel: Draw=DrawSquare;}
Draw(Image);
II
;
void TFigure: :DrawCircle(TImage Vmage)
{Image->Canvas->Ellipse(x-r, y-r, x+r, y+r); }
void TFigure:: DrawSquare (TImage 4mage)
fImage->Canvas->Rectangle(x-r, y-r, jc+r, y-^r);}
void TFigure:: Clear (TImage "^Image)
{Image- > Canvas- >Pen- > Color=cl White;
Draw(Image); II ,
Image->Canvas->Pen->Color=clBlack; }
#pragma package (smart_init)
Figure :
void_ J'astcall TMainForm::ImageMouseDown(TObject "^Sender,
TMouseButton Button, TShiftState Shift, intX, int Y)
{ if (Figure !=NULL) delete Figure; II ,
Figure=new TFigure(X, Y, 10,Image,RadioGroup); II
:
265
. + + Builder
6.1. C+ +
.
, RTTI
( ), C++
.
,
:
class {virtual '-^(9/;?^;/*
, RTTI*/
class : public {virtual-(){}};
voidfunc(A& ) /* , */
{BiSc b=dinamic_cast<B&>(a); II
}
void somefuncQ
{ Bb;
func(b);
II
dynamiccast ,
, ,
NULL (0),
. :
if (Derived* q=dinamic_cast<Derived* >)
/^< , ... >^
else {<QCjm , ...>
( RTTI).
, NULL q=NULL,
else.
,
bad_cast. :
Derived* q=dinamic_cast<Derived* >;
: static__cast<T>(t).
: - , , ;
t - , .
.
.
267
6. C++ Builder
:
1) :
i;floatf=static_cast<float>(i);/*
*/
2) , :
int *q=static_cast<mt>(malloc(100)); /*
*/
3)
, .
,
,
:
class {...}; II
class : public {}; II
void somefuncQ
{ ; ;
& ab-static_cast<B&>(a); II
AiSc ba=static_cast<A&>(b); II
}
. ,
. coiist__cast<T>(t) -
const volutile reiiiterpret<T>(t) -
, .
,
.
. -- Buider DelpM Pas
cal . Delphi Pascal
(.
5.3). C++ Builder
Delphi Pascal.
Delphi Pascal : , -
.
:
property < > <> = {< >};
,
:
268
6.1. C+ +
II -
II
II
II
II
269
6. + + Builder
, :
^property int Number={read=GetNum}; II " "
pNumber- > Number=6;
.
- :
property <> <> [< >] = {< >};
.
.
C++.
- stored default
, , :
property int Mas[int i][intj]={read=GetMas, write=SetMas}; {
- Mas }
, -,
,
(. 5.3). ,
,
.
.
6.4. - ( ).
C++ ,
5.8.
, C++ Builder
6.2.
- array.h:
class TMasByte
{ private:
unsigned char * ptr_an;
II
unsigned char len;
II
void SetEl(short Ind, unsigned char m); II
unsigned char GetEl(short Ind);
II
public:
unsigned char n;
II
270
6.1. C+ +
.:
TMasByte:: TMasByte(unsigned char alen)
{ ptr_an='new unsigned charfalenj; len=alen; n=0;}
TMasByte: -TMasByteQ
{ delete [] ptrjin;}
void TMasByte::SetEl(short Ind, unsigned char m) II
{if(Ind<len)
if(Ind<n) ptr_an[Ind]=m;
else throw (' ,");
else throw ('' .");}
unsigned char TMasByte::GetEl(short Ind)
II
f if(Ind<n) return ptrjm[Ind];
else throw (" .") ; }
void TMasByte:: Modify (short Ind,unsigned char Value)
{ Mas[Ind]=Value;}
void TMasByte::Insert(short Ind,unsignedchar Value)
{ ++;
for (short i=n-l;i>Ind;i) Mas[i]=Mas[i'l];
Mas [Ind]=Value;}
unsigned char TMasByte: :Delete(short Ind)
{ unsigned char Result=MasfInd];
for (short i=Ind;i<n-l;i-^-^) MasfiJ=Masfi+lJ; n;
return Result; }
void TMasByte: :InputMas(TStringGrid'^ Gridjnt ijntj)
{ int k=0;
while (Grid'>Cellsfk+i]/jJ.LengthO)
(try { unsigned char x=StrToInt(Grid'>Cellsfk+iJljJ);
if(x<255) Insert(k,x);
else throw (" 255');
^+;
catch (EConvertError&)
{throw (' ");}
}
271
6. + + Builder
OutputMas(Grid, ij);}
void TMasByte::OutputMas(TStringGrid* Gridjnt ijntj)
{ if(n+i>Grid'>ColCount) Grid->ColCount=n+l;
for (int k=0;k<Grid->ColCount;k++)
if(k<n)Grid->Cells[i+k][j]=IntToStr(Mas[k]);
else Grid->Cells[i^k][]]=""; }
TMasByte
:
TMasByte *;
II -
=new TMasByte(lO);
II
A->InputMas(DataStringGrid, 0,0); II >1
'>Insert(Ind, Value);
II
A->OutputMas(DataStringGrid,0,0); II
delete ;
II
index, :
property <> <> = {< >, index = <>};
,
, -.
:
private:
int/Region f3J;
int GetRegion(int index);
void SetRegionfint indexjnt value);
public:
__property int Region!={read=GetRegion, write=SetRegion, index=0};
property int Region2={read=GetRegion, write=SetRegion, index=l};
property int Regions={read=GetRegion, write =SetRegion, index=2};
, ()
fRegion,
, :
int < > ::GetRegion(int index) {return fRegion [index];}
void < Knacca>::SetRegion(int indexjnt value) {fRegion[index]=value;}
,
- ;
272
6.2.
- , ;
- ;
- , .
6.2.
1.7 5.8,
,
-
( ,
, ..).
,
() ,
.
.
, C++
.
C++. C++
throw, try catch. - ,
~ .
,
.
throw :
throw [<>](<>);
<> - ( ) ; ,
(
); <> - ,
.
:
1)
throw ('' "); /*
const char * */
2)
throw (221); /* const int
5 */
3)
class { //
public: int ;
II
E(int ): (){} II
;
throw (5); II
273
6. + + Builder
try ... catch .. .(catch...):
try {< >}
catch (< >){< >}
try ,
.- catch .
catch , ,
try
, catch. :
- , const
, & const &;
-
;
- void* .
catch, ...,
.
:
try {<>} II
catch (EConvert& ){<>} /*
EConvert */
catch (char* ){<>} /* char* */
catch(...) {<>}
//
,
.
.
, void*
char*, char*
void*.
.
:
class {};
class :public {}; ...
try{...}
catch (& ) {,..} II
catch (& ){...} II
,
.
274
6.2.
throw ,
, .
.
:
class {};
II
voidsomefuncQ
{[/<> throw OutQ; }ll ,
voidfuncQ
{ try
{somefunc(true); }
catch (& e){ if (<y) throw;} /*
, */ }
void mainfuncQ
{try
{funcO; }
catch(E& e){,.. } } II
. 6.1.
somefunc .
, ..
, . ,
sumefuncO func(), ,
,
. , ,
,
.
- mainfimc().
, fiinc .
catch , .
catch
. :
somefunc()
func()
mainfimc()
. 6.1.
275
6. + + Builder
class //
{ public: int ;
II
E(int ): () {} II
;
throw (5);
II
:
throw(<THn>,<THn>...).
:
voidJune throw(char*,int){...} /*
char* int */
,
,
, :
class ALPHA
{public:
struct ALPHA_ERR {}; virtual void vfuncQ throw (ALPHAJERR) {}
II
}:
276
6.2.
277
6. + + Builder
,
, :
=new TMasByte(lO);
try {A'>InputMas(DataStringGridAO);}
catch (char* Mes)
{ TMsgDlgButtons Set2;
Set2mbOK;
MessageDlg(Mes,mtInformation,Set2,0); }
C++ Builder
.
.
_ ^finally:
try {< >}
^finally {< >}
,
.
.
.
_ _try... ^except ^try... ^finally.
, ~ .
:
try {< >}
_ _except(<pyee >)
{< >}
:
- EXCEPTION_EXECUTE_HANDLER -
(
,
);
- EXCEPTION_CONTINUE_SEARCH -
;
- EXCEPTION_^CONTINUE_EXECUTION -
, (
).
278
6.2.
, ,
.
excpt.h ,
:
GetExceptionCodeO - .
GetExceptionlnformationO - ,
.
:
except(), :
Uincltide <excpt.h>
intfilter Junc(EXCEPTION_POINTERS
V;
EXCEPTION_POINTERS Hp = 0;
try{
fooO; }
__except (filterJunc(xp = GetExceptionlnformationO)) //*
*/ }
:
except (( = GetExceptionlnformationO), filterJunc(xp))
GetExceptionlnformation (),
. GetExceptionlnformationO
EXCEPTION_POINTERS:
struct EXCEPTION_POINTERS {
EXCEPTIONJiECORD *ExceptionRecord;
CONTEXT *Context;
};
EXCEPTIONRECORD
:
struct EXCEPTIONJiECOKD
{ DWORD ExceptionCode; II
DWORD ExceptionFlags; II
struct EXCEPTION RECORD *ExceptionRecord;
void *ExceptionAddress; II
DWORD NumberParameters; II
DWORD Exceptionlnformation
[EXCEPTION_MAXIMUM_PARAMETERS];
/* */
}:
279
6. + + Builder
ExceptionRecord, ,
.
, ,
CONTEXT.
, ,
(
EXCEPTION_CONTINUE_EXECUTION),
.
CONTEXT, , :
static int xfilter(EXCEPTION_POINTERS *xp)
{ int re;
EXCEPTIONJRECORD *xr = xp->ExceptionRecord;
CONTEXT *xc = xp->Context;
switch (xr'>ExceptionCode)
{ case EXCEPTION_BREAKPOINT
+-^xc->Eip; /*
, 1 */
= EXCEPTION_CONTINUE_EXECUTION;
break;
case EXCEPTION_ACCESS__VIOLATION:
re = EXCEPTION_EXECUTE_HANDLER;
break;
default:
II
re = EXCEPTION_CONTINVE_SEARCH;
break;
};
return re;
}
EXCEPTION JOINTERS *xp;
try{
JuncO; }
except(xfilter(xp = GetExceptionInformation())) { abortQ;
void Raisexception(DWORD < >, DWORD <>,
DWORD < >,
const DWORD *< 32- >);
<> :
EXCEPTION_CONTINUABLE - ;
EXCEPTION_NONCONTINUABLE - .
280
6.2.
:
#include <excpt.h>
Mefine MY_EXCEPTION OxOOOOFACE
voidfimcQ
{ RaiseException(MY_EXCEPTION,
EXCEPTION_CONTINUABLE, 0,0);}
DWORD ExceptionFilter(DWORD dwCode)
{if(dwCode==MY_EXCEPTION)
return EXCEPTION_EXECUTE_HANDLER;
else return EXCEPTION_COUNTINUE_SEARCH; }
void somefuncQ
{try{funcO;}
except(Exception Filter(GetExceptionCodeQ)) {...}
}
, ,
:
try {{< > }
finally {< >}
, , -+:
try {< >}
finally {< >}
:
try
float/=1.0, g = 0.0;
try {e =f/g;} //
_ _except(EXCEPTION_EXECUTE_HANDLER)
Z'< > }
_ finally
{ < > ^
,
, .
, .
,
Win32.
.
Windows NT,
281
6. + + Builder
6.3. '
#include "Exception.h"
MyException::MyException(char* s = "Unknown"){what = strdup(s); }
MyException: :MyException(const MyException& e){what = strdup(e.what);}
MyException::'--MyExceptionQ {delete[] what;
}
char"^ MyException::msgO const{return what;}
float func(floatffloat g)
{float r^O;
try
{try
{try
{r^f/g;}
except(EXCEPTIONj:XECUTE_HANDLER)
{throw (MyException(" ")); }
}
catch(const MyException& e)
{ ShowMessage(AnsiString(e. msgQ));}
}
_ ^nally {ShowMessage(" ");}
return r;
}
^pragmapackage (smart jinit)
:
RezEdit'>Text=FIoatToStr(func(StrToFloat(DivEdit'>Text),
StrToFloat(DvEdit->Text)));
. , ,
, +-\- Builder, Delphi, ,
. ,
.
6.3. VCL-
VCL, Delphi Pas
cal, VCL- . Delphi Pas
cal, TObject.
C++ :
- OLE-
( published, _ ^automated);
- (_ __declspec);
- ;
- .
VCL- . VCL-
:
1)
( );
283
6. - + Builder
2) VCL-
new, delete;
3) ;
4)
.
VCL- C++ Builder
:
class < >:
< > < >
{ private:
< >
protected:
< >
public:
< >
published: < >
automated: <, ->
};
C++ VCL published automated
, Pascal Delplii.
published (. 5.1) ,
,
.
.
,
RTTI (
),
, .
,
TObject.
. , ,
VCL ( ).
, ~ (
- ) : ,
, , , .
automated ,
OLE-.
6.3. '
^declspec(delphireturn) - ,
C++Biiilder Delphi Pascal,
C++, , AnsiString, Variant, TDateTime, Set,
VCL.
VCL-
VCL. ,
Delphi Pascal C++.
declspec(dyiiamic) -
(. 5.2) , TObject.
6.6. ,
. class 1 statfunc(),
virtfuncO dinfunc() .
class2 .
Object.h:
class
declspec(delphiclass) class 1: public TObject
{public:
char* polyfuncQ;
virtual char* virtfuncQ;
declspec(dynamic) char* dynfuncQ;
};
class
declspec(delphiclass) class2 : public class 1
{public:
char* polyfuncQ;
char* virtfuncQ;
char* dynfuncQ;
};
Object.cpp:
^include "Object.h"
char* classl::polyfuncQ{return " ';}
char*classl:.virtfuncQ{return " 1";}
char* classl::dynfuncQ {return " 1";}
char* class2:.polyfuncQ{return " 2";}
char*class2:.virtfuncQ{return "2";}
char* class2::dynfuncQ {return " 2";}
class2
:
class2 * Class2 = new class2;
classl * Classl = Class2;
285
6. + + Builder
:
Edit->Text-Classl'>polyfuncO;
Edit'>Text=Class2'>polyfuncO;
Edit'>Text=Classl'>virtfuncO;
Edit'>Text=CIass2->virtfuncO;
Edit->Text=Classl'>dynfuncO;
Edit'>Text=Class2->cfynfuncO;
// 1 (!!!)
II 2
// 2
// 2
II 2
// 2
,
( ) .
.
declspec(hidesbase) - C++,
, ,
, .
, Delphi Pascal
override,
virtual
.
C++ hidesbase.
, 1 firnc
, 2
, fimc,
HTOESBASE:
virtual void Tl::func(void);
HIDESBASE void T2::func(void);
T2::func()
1 ::func().
declspec(package) - ,
. DLL ,
C++ Builder.
declspec(pascalimplemeiitation) - , ,
, Delphi Pascal.
.hpp,
VCL.
^declspec (dllimport) -
DLL.
DLL C++Builder
.
, ALLLIB.
L
286
6.3. '
LFLAGS ( ).
DLL .
DLL declspec(dllimport), :
declspec(dllimport)
<> < >(<>);
DLL
Windows API LoadLibrary()
GetProcAddressO - .
. ,
- Delphi Pascal C+-I-,
, .
. Delplii Pascal ByteBool,
WordBool, LongBool , - .
Boolean - ,
- . +- .
, M^nAPI
BOOL ( ).
,
0. ,
! = !:
A.ByteBool
0 (False)
0 (False)
-1 (Trae)
-1(True)
BOOL
0 (False)
1 (True)
0 (False)
1 (Trae)
A=B
!A=!B
0=0 (Trae)
!0 = !0 (Trae)
0=1 (False)
!0 = !1 (False)
-1=0 (False) !-l = !0 (False)
-1=1 (False!) !-l = !l (Trae)
. C++ - , Delplii
Pascal - . ,
, .
.
- Pascal
. C++
(-1).
,
Junction Mean(Data: array ofDouble): Extended;
C++
Extended _ Jdstcall Meanfconst double * Data, const int DataSize);
287
6. + + Builder
C++
:
double d[] = {3.1, 4.4, 5.6}; long double = Mean(d, 2);
TObject.ClassName, ,
,
C++ - name(). ,
TObject (.
5.4).
VCL- . VCL Delphi Pas
cal. , ,
.
C++ Builder
, ,
, ..
Exception (. 5.8).
C++:
catch (< > &<1>)
, C++,
288
6.3. '
, :
voidjastcall
TForml::ThrowException(TObject ^Sender)
{ try { throwExceptionC'VCL component"); }
catch(const Exception &E)
{ShowMessage(AnsiString(E.CIassNameO)+ E.Message);}
}
,
.
5.8.
, , .
C++ VCL:
1. , - ,
, VCL - ,
.
2. C++ ,
, VCL ~ .
.
, EAccessViolation,
.
3. , ,
throw. ,
VCL C++,
catch.
4. VCL
.
5. VCL .
,
, , ..,
VCL. .. VCL :
try{ char * = 0;
* = 0;}
catch (constEAccessViolation &)
/^< >^
VCL-
.
289
6. C++ Builder
6.7. VCL-
.
(. 6.2).
C++ Builder
TMainForm, -
,
.
Main.h:
^include <Classes.hpp>
#include <Controls.hpp>
^include <StdCtrls.hpp>
^include <Forms.hpp>
^include <ExtCtrls.hpp>
Mnclude <Grids.hpp>
class TMainForm : public TForm
{
published:
II
TLabel *MaxSizeLabel; II
TEdit *McixSizeEdit; II
TBevel *Bevell;
II
TButton *ModifyButton; II
TButton VnsertButton; II
TButton *DeleteButton; II
TButton *DataButton; II
TButton *ExitButton; II
TStringGrid "^DataStringGrid; II
TLabel 4ndexLabel;
II
TLabel *ValueLabel;
II
fjji
f1
45
10
liniiimi"..n
. 6.2.
290
6.3. '
TEdit VndexEdit;
II
TEdit *ValueEdit;
II
TLabel *CommentLabel; II
void_ Jastcall ExitButtonClick(TObject Sender); /*
" " */
void_ Jastcall ModifyButtonClick(TObject "^Sender); /*
" " */
void__ Jastcall DataStringGridKeyPress(TObject "^Sender, char &Key); /*
" " */
void_ Jastcall InsertButtonClickfTObject *Sender); I*
" " */
void_ Jastcall DeleteButtonClick(TObject "^Sender); /*
" " */
void__ Jastcall DataButtonClick(TObject ^Sender); /*
" >1" */
void__ Jastcall FormActivatefTObject *Sender); /*
" " */
private:
II
public:
II
_ Jastcall TMainForm(TComponent* Owner); II
_ Jastcall --TMainFormQ;
II
};
extern PACKAGE TMainForm *MainForm;
#endif
Main.cpp.
(
Delphi Pascal, ,
, AnsiString,
..):
#include <vclh>
Upragma hdrstop
^include "Array, h"
mnclude "Main,h"
^pragmapackage (smart Jnit)
^pragma resource "*.dfm"
TMainForm *MainForm;
TMasByte*A;
Jastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner)
{ A=new TMasByte(lO);}
fastcall TMainForm: .-TMainFormQ { delete A;}
void
fastcall TMainForm::ExitButtonClick(TObject*Sender) { CloseQ; }
void Jastcall TMainForm: :ModifyButtonClick(TObject ^Sender)
291
6. + + Builder
6.3. '
AnsiString '");
TMsgDlgButtons Setl;
SetlmbOK;
try {Ind-StrToInt(IndexEdit->Text); /* ,
*/
Num=" ";
Value=StrToInt(ValueEdit'>Text);
A'> Insert (Ind, Value);
A'>OutputMas(DataStringGrid, 0,0); }
catch (EConvertError&)
/* "
" */
{AnsiString s=" ";
MessageDlg(s+Num,mtInformation,Setl, 0); }
catch (char * Mes) /*
*/
{MessageDlg(Mes,mtInformation,Setl,0); }
}
void _ Jdstcall TMainForm: :DeleteButtonClick(TObject "^Sender)
{ short Ind; TMsgDlgButtons Setl;
SetlmbOK;
try {Ind=StrToInt(IndexEdit'>Text);
A'>Delete(Ind);
A'>OutputMas(DataStringGrid,0,0); }
catch (EConvertError&)
{MessageDlgC'HeeepHO .", mtlnformation, Set 1,0);
}
catch (char "^ Mes)
{ MessageDlg(Mes,mtInformation,Setl ,0); }
}
void _ J'astcall TMainForm: :DataButtonClick(TObject ^Sender)
{ FormActivate(DataButton);}
void _ J'astcall TMainForm: :FormActivate(TObject "^Sender)
{ CommentLabel-> Visible =true;
if (dynamic_cast<TButton*>(Sender)) II - ,
{for (int i=0;i<10;i-^-h) DataStringGrid'>CellsfiJfOJ="";
TGridOptions Setl;
Setl =DataStringGrid'> Options;
Setl < <goEditing< <goAlwaysShowEditor< <goTabs;
DataStringGrid'> Options =Set 1;
DataStringGrid->Enabled=true;
DataStringGrid'>Col=0;
DataStringGrid->SetFocus0;
delete A;
A=new TMasByte(lO); I* */ }
}
293
6. C++ Builder
6.4.
C++, Delphi -- Builder
-- Builder
-+, Delphi
C++ Builder.
Pascal C++
.
VCL C++ Builder
C++, Delphi.
.
.
C + + . C++
:
- ;
- ;
- .
. ,
, ,
.
Borland
Pascal
7.0 Delphi. Delphi Pascal
, ,
.
inherited (. 5.1),
.
.
.
, , ,
.
C + + Builder.
VCL- C++ Builder
Delphi Pascal, C++.
, VCL-
.
VCL.
VCL, inherited.
, C++, ,
VCL.
Delphi
Pascal.
C++.
. 6.3 , ,
VCL.
294
TObject
TPersistent
D
e
1
P
h
i
TComponent
TControl
TWinControl
TMyBase
)
TWinControl
(inherited)
TControl
(inherited)
T
TComponent
P
a
s
a
1
!1|1!111111|
llljllllllllllijll
C++
TMyBase
Builder
TMyDerived
a
^
TMyDerived
. 6.3. ,
VCL
MyDerived MyBase, VCL
TWinControl. MyDerived MyBase +- Builder.
T\V^Control VCL, .. Delphi Pascal.
. TComponent inherited,
TPersistent . TObject ,
.
.
C++
. , ,
C++,
, . VCL-
,
,
.
6.8
C++ VCL. MyBase MyDerived C++.
MyVCLBase MyVCLDerived TObject ( VCL).
295
6. C++ Builder
virtfunc () ,
.
6.8. C++ VCL . :
C++, - VCL:
class MyBase
II VCL
{ public:
MyBase(TEdit "^Edit); II
virtual void virtfunc(TEdit *Edit);
h
class MyDerived: public MyBase
{public: MyDerivedfTEdit *Edit);
virtual void virtfunc(TEdit *Edit);
};
class MyVCLBase : public TObject
II VCL
{ public:
fastcallMyVCLBase(TEdit ""Edit);
virtual void _Jdstcallvirtfunc(TEdit *Edit);
}:
class MyVCLDerived: public MyVCLBase
{ public:
fastcall MyVCLDerived(TEdit ""Edit);
virtual void _ Jastcall virtfunc(TEdit *Edit);
}:
:
MyBase: :MyBase(TEdit "^Edit) { virtfunc(Edit);}
II
void MyBase: :virtfunc(TEdit *Edit){Edit'> Text = " ";}
MyDerived::MyDerived(TEdit*Edit):MyBase(Edit){}
voidMyDerived::virtfunc(TEdit *Edit)
{ Edit'>Text="Memod ";}
fastcall MyVCLBase: :MyVCLBase(TEdit *Edit) {virtfunc(Edit);} //
void fastcall MyVCLBase ::virtfunc(TEdit "^Edit)
{Edit'>Text="Memod ";}
_JastcallMyVCLDerived::MyVCLDerived(TEdit*Edit):MyVCLBase(Edit){}
void fastcall MyVCLDerived: :virtfunc(TEdit *Edit)
{Edit->Text = " ";}
,
:
296
MyDerivedd(Editl);
II :
MyVCLDerived "^pvd = new MyVCLDerived(Edit2);
//:
,
,
C++, - . ,
, -
.
. Delphi Pascal .
, VCL.
C++ .
. ,
,
, .
6.9.
VCL- . VCL- :
class Base : public TObject
{public: __Jdstcall BaseQ;
virtual void _ Jdstcall initQ;
};
class Derived: public Base
{public: _ Jdstcall Derived(intnz);
virtual void _ Jdstcall initQ;
private: int not zero;
};
:
_JastcallBase::BaseO
{initQ;}
void _ Jastcall Base:: initQ {}
_Jastcall Derived::Derived(intnz) : not_zero(nz) {}
void _ Jastcall Derived:: initQ
{if(not_zero == 0) throw Exception("none not zero !'*);}
:
Derived *d42 = new Derived(42); II
, Base Derived
, , notzero Delphi Pascal.
297
6. + + Builder
,
.
.
C++ Builder :
Delphi Pascal C++.
. - . VCL .
. , , :
class
{...};
class : public {...};
class : public {...};
, .
C++
,
. .
Delphi Pascal
. .
inherited.
, , , ,
- ,
. ,
,
. ,
, ,
.
C++Builder , VCL, Delphi Pascal,
, Delphi Pascal.
VCL- , C++Builder,
. ,
, ,
C++, .
. .
,
. , VCL,
,
..
, ,
, . TObject
: BeforeDestruction AfterConstruction,
,
298
.
AfterConstruction ,
BeforeDestruction - .
.
6.10. .
, ,
.
: , , ,
.
, - .
, , .
, .
.
(. 6. 4).
,
: , ,
. , .
.
| | |
|=)(+2^
: IQ
1 -1
| h g
|1
1;
. 6.4.
299
6. + + Builder
. TMainForm
TForm,
:
string,
xb,
xe,
h,
win
TDiagram
: TDiagram, Draw
.
TFunction ()
:
TDiagraml,
Draw
TDiagraml
. TDiagram
() TImage,
TDiagraml (
. 6.5.
) - TDiagram,
TImage-TDiagram-TDiagram 1
Draw (. 6.5). Draw
TDiagram, , ,
. TDiagram TDiagraml
TImage, .. VCL-, ,
.
.
,
(. 6.6).
llJll^^^^^^
clj
^ >^
<^ \^
1 - ;
2 - ;
-
. ..
.
Main ( TMainForm):
1. Main.h
mjhde/MainH
Meflne MainH
#include <Classes.hpp>
Mnclude <Controls.hpp>
Mnclude <StdCtrls,hpp>
Mnclude <Forms.hpp>
^include <ExtCtrls,hpp>
class TMainForm : public TForm
/1_ J>ublished:
II IDE-managed Components
TButton *BuildButton; TButton *ExitButton;
TPanel *Panel; TPanel VmagePanel;
TLabel *FLabel; TEdit *FEdit;
300
6. +- Builder
}
void _ Jdstcall TDiagraml:: Draw (char "^stfloat xb float xe float h)
{ CanvaS'>Rectangle(win,Left,win. Top,win.Right,win.Bottom);
TDiagram::Draw(st,xbyXe,h); //
}
^pragma package (smart_init)
FunctionUnit ( MyFunction):
1. FimctionUnit.h
#ifhdefFunctionUmtH
Mefine Function UnitH
struct Top {char Operation; float Value; Top 4eft, "^rigth;};
class MyFunction
{private: char "^string;
Top *root;
unsigned int MainOperation(char *st, char );
voidBuildTree(Top *r,char ^^st);
float FCount(Top "^rfloat x,bool &key);
void Del(Top *r);
public:
MyFunction(char "^formula);
^MyFunctionQ;
float Count (float x, bool key);
};
#endif
2. FunctionUnit.cpp
Mnclude <string,h>
Mnclude <stdlib,h>
Mnclude <matkh>
#include <vcl.h>
#pragma hdrstop
Mnclude 'FunctionUnit.h"
unsigned int MyFunction::MainOperation(char *st, char )
{ unsigned intj=0,k'=0,i=0,p=0;
while ((i<strlen(st))&(p==0))
{if(st[iJ==r)J++;
elseif(st[ij==)')k-i-+;
else if(0==k)&(strchr(Op,stfi])!=NULL))p=i;
return p;
303
6. + + Builder
MyFunction::MyFunction(char "^formula)
{root=new Top; string=new charfstrlen(formula)+lJ;
strcpy(stringJbrmula); BuildTree(root/ormula); //
;
else { r->left=NULL;r->rigth=NULL;
if(st[0]=='x') r->Operation='x';
else {r->Operation-'o';r-> Value=atof(st);}
}
}
void MyFunction: :Del(Top *r)
{if(r'>rigth!=NULL) Del(r->rigth);
if(r'>left!=NULL) Del(r->left);
delete(r); }
MyFunction: :'-MyFunction()
{ delete[]string; if (root! =NULL) Del (root);}
float MyFunction: :FCount(Top "^rfloat x, bool &key)
{if(!key) return 0;
switch ('>Operation)
{case 'o':return'>1;
case 'x':return x;
case '-^':return FCount(r'>left,x,key)+FCount(r->rigth,x,key):
case ''':return FCount(r->left,x,key)-FCount(r'>rigth,x,key);
case "^':returnFCount(r'>left,x,key)*FCount(r->rigth,x,key);
case '/': try (return FCount(r'>left,x,key)/FCount(r'>rigth,x,key);}
except (EXCEPTION_EXECUTEJIANDLER){key=false;return
default: {key-false; return 0;}
304
0;}
}
}
float MyFunction:: Count (float :, bool key)
{return FCount(root,x,key);}
fi'pragma package (smart_Jnit)
1. C-i-fBuilder ?
?
2. C++?
?
3. C++Builder ?
. ? ?
4. VCL- ?
, .
5. VCL ? ?
6. ( Delphi) ,
. .
5.9. .
:
, Delphy, C++ Builder Visual +-,
,
~ , .
,
,
.
. ,
,
.
. , ,
.
.
1
1. . - : .
. .: , 1997. 464 ,
2. . -
C++: . aimi. .: , .: , 1998.
560 .
. , ., .. : . .
.:, 1975.247 .
4. /., . : .
. .: , 1980. 278 .
2
1. .., .. -
( 5.5). .: - , 1992. 576 .
2. . . - 3 . . 1. -. .:
- , 1992. 304 .
3
1. .., . C++. .: -,
1997.288 .
307
6
1, ., . Borland C++Builder. .: , 1997. 272 .
2. . Borland C++ Builder 3. : . . .:
, 1999. 736 .
19,21,23
28
25, 50, 196, 299
11
76, 152
38,76, 110,152
135
20
55, 251, 273
56,254,273
254, 274
252, 278
133, 203
108
22, 35, 41, 68, 255
20, 63, 123, 205
52, 108, 161,223
35, 59, 99, 192
54, 154,
45, 86
38, 70, 110, 194,295
114, 126, 146, 159
, 151
151
310
48,219
133, 203, 144
69, 130, 202, 285
49, 228, 263
202, 285
222
207,262
42, 67, 129, 162
42, 67, 130, 161
109, 285
18, 20
127, 137
40, 125
40, 63, 118
18
44, 86
77, 85, 144
34
44,266
33
41, 70
29
60
77, 144
32
38, 144
179
180, 200
246
33, 174
247
174, 241
241
174, 249
56, 275
21
22
42, 165
-
22
23
RTTI48, 220
44, 132,220
1
1.1. (
)
14
1.2. (
)
26
1.3. ( )
28
1.4.
29
1.5. ( )
30
1.6. ( )
36
1.7. ( -
1.5)
38
1.8. ( )
40
1.9. ( )
42
1.10.
1.11. ( -
1.5)
43
46
1.12. ( )
47
1.13. ( )
50
1.14. ( )
53
312
1.15.
( )
54
1.16. ( )
55
2
2.1. ( )
61
2.2.
( )
64
2.3. 1 ( )
66
2.4.
68
71
2.6.
72
2.7.
77
2.8.
78
2.9. (
)
79
2.10.
84
2.11.
86
2.12. -
87
2.13.
92
3
3.1. ( )
101
3.2.
103
3.3. this
105
313
3.4.
107
3.5.
108
3.6.
3.7.
111
3.8.
112
3.9.
113
3.10. ....
115
3.11.
116
3.12.
118
119
3.14.
private
3.15.
3.16.
120
122
123
3.17.
125
3.18.
128
3.19.
129
3.20.
3.21.
131
133
3.22.
135
3.23. -
136
314
3.24.
137
3.25. -
139
3.26. -
140
3.27.
+
141
3.28. -
143
3.29.
145
3.30.
146
3.31.
149
3.32.
150
3.33.
152
3.34. ,
154
3.35.
155
3.36.
156
3.37. (
)
157
3.38. ....
161
3.39.
165
4
4.1. ( 1) ....
182
4.2. ( 2) ....
188
315
5
5.1. ( 1)
;
196
5.2. (
- 1)
204
5.3. (
- 2)
212
5.4. - (
- 1)
215
5.5.
223
5.6. (
- 2)
229
5.7. - (
)
238
5.8. /
244
5.9.
246
5.10.
249
5.11. (
- 2)
256
6
6.1.
( using)
262
6.2. (
)
264
6.3. ( )
269
6.4. - ( )
270
6.5.
282
316
6.6. ,
285
6.7. VCL-
290
296
6.9.
VCL-
297
6.10.
299
..
.. , ..
. .
..
. . 020523 25.04.97
27.03.2001. 70x100/16. .
. . . . 26. .-. . 26,28. 3000 . 1459
. . . ,
107005, , 2- , 5.
-
121099, , ., 6