-
1
" "
Object-Oriented Programming (- - ) . - , . . - .
(Object) - , , , , . (encapsulation). , , , . .
(instance) . , -, , .
(Class) - () (), . - , . () , .
(inheritance), / , . , . , .
- , -, (polymorphism). - , , . , - .
(Record) , . , . . . (), .
|
|
, . , , , . .
, , .. , . . , . , - , . , , . . , .
, : . Delphi , .
, - Object Pascal (OP). , ( ).
- , , . OP (object reference model), .. , () , , .. - . , OP , '^' - caret.
, . , .. - , . , , , . , , , .
, , , , , - . , .
|
|
, , , . , .. , () .
, , .. , .
) , .. , , :
Type < >= lass [(< >)}
> // ,
End;
:
, . , . .
, Forward'.
Type < >= lass [(< >)};
OP - TObject. TObject .
() . -: Private, Protected, Public, Published ( SM+). , - . Public.
, :
, ;
' ;
- , .
.
, F.
: :
- , . . , , . Delphi :
- , . , - 4 .
() , .. . - ( , ), ( , ). , , : , ..
. " " , , . , , DDE- ..
|
|
) . Var, .
) . :
( ):
< >.< >:=<>;
With, :
With < > Do Begin
< ]>:=<1>;
< 2>:=<2>;
...
End;
, .
TLine:
Type TLine=Class
X, Y, Length, Angle: Integer; //
Constructor Create; //
Procedure MoveTo(NewX, NewY: Integer); // 1-
Procedure Rotate(ByAngle: Integer); // 2-
End;
, :
Var ALine: TLine;
Begin
...
ALine:=TLine.Create; // ALine
...
() :
...
ALine.X:=10;
ALine.Y:=10;
ALine.Length:=100;
ALine.Angle:=30; //
(-) :
Type
TColorLine=Class(TLine)
Color: TColor; // -
Width: Integer; // -
Constructor Create; //
End;
:
Var AColorLine: TColorLine;
Begin
AColorLine:=TColorLine.Create;
AColorLine.Color:=clRed;
AColorLine.Width:=2;
ACoIorLine.X:=20; //
AColorLine.Y:=20
, TColorLine , TLine, .
- , . , . ( ), . :
-, , , "" , , - ;
-, , , , -;
, , -. . (.. ), ;
, , ;
- , . , , , . - ;
- , -. , , .. . .
|
|
:
:
( , ) , , . Forward ;
- (Implementation) , , Begin End.
,
.
,
:
[ Self. ] < >[(<>)];
.
, , .
,
.
TObject 25 (Delphi 5) :
, , Free, 9 .
. (-), : Class, Virtual, Dynamic, Abstract, Override, Overload, Reintroduce, Message.
Delphi 4.0 TObject AfterConstruction BeforeDestruction, , .
- -
- - , , , ( Begin), .
) :
Type
< >= Class [(< )]
Procedure < >[(<>)];
Function < >[(<>)]: < >;
End;
Type TPictureShow=Class //
FFilm: TFilm; //
FTitle: String; //
Function GetFilm: TFilm;
Procedure SetFilni(Const AnFiIni: TFilm);
Function GetTitle: String;
Procedure SetTitle(AnTitle: String);
End;
) .
- -:
Procedure < >.< >[(<>}];
[< }
Begin
< >
End;
Function < >.< >[(<>)}:< >
[< >]
Begin
> Rs1t:=< >;
> End;
Function TPictureShow.GetTitle: String;
Begin
Result:=FTitle;
End;
Procedure TPictureShow.SetTitle(AnTitle: String);
Begin
FTitle:=AnTitle;
End;
:
Procedure\Function, :
< >.< >[{<>)];
- < >.
, Result .
, , , Self, .
) .
, , . , . , . , , .
:
< >.< >[(<>)];
:
With, , Delphi .
|
|