Delphi , . , .
type .
class end. , . , .
:
type className = class (ancestorClass) memberListend; |
MemberList , .
:
Type TClassName = class(TParentClass) private... { private declarations here} protected... { protected declarations here } public... { public declarations here } published... { published declarations here } end; |
:
1. TparentClass , Tobject, constructor destructor.
2. .
3. , : private, protected, public, published.
- Private. , private . private , .
- Public. , , public , .. . , public, .
- Protected. , , protected, ; . private, protected , , , . .
- Published. , public. , , published, . , . published , $TYPEINFO.
4. , , .
5. private, protected, public published, , public, , VCL, published.
|
|
6. , , .
:
TYPE TCoordinates=record X,Y:Integer; end; Tfigure = classprivateFcolor:TColor;Coords:TCoordinates; ProtectedProcedure setColor(c:TColor); virtual;Procedure Draw; virtual; abstract;Procedure Hide; virtual; abstract;Procedure Move(NewX,NewY:Integer);Property Color: TColor read Fcolor write setcolor;End; |
(Fcolor, Coords) (Draw, Hide, Move). , () , (forward) . .
, . : . :
type TReadersList = class; // TReadersList TDelimitedReader = class Owner: TReadersList;... end; TReadersList = class Readers: array of TDelimitedReader;... end; |
TDelimitedReader ( . forward). , Owner TDelimitedReader.
. interface, implementation. , :
- , , interface;
- , , implementation;
- B A, B , A.
, var:
var Figure: TFigure; |
. Delphi , .. . Figure ( ), .
( ) TFigure Figure, :
Figure:= TFigure.Create; |
Create ; . . , , ; .
: , . , :
|
|
Figure.Move; |
, , with, :
with Figure do Move; |
, Destroy, :
Figure.Destroy; // , |
Destroy ; . Figure . , nil. , Destroy , :
Figure:= nil;...if Figure <> nil then Figure.Destroy; |
.
, Free, . Free Destroy, , nil. .
Figure.Free; |
Figure , , . , nil, , . , :
Figure.Free;Figure:= nil; |
FreeAndNil :
FreeAndNil(Figure); // : Figure.Free; Figure:= nil; |
. , , :
var R1, R2: TFigure; // R1 R2 begin R1:= TFigure.Create; // R1 // R2 R2:= R1; // R2 , R1 // R2.Free; // // R1 R2 end; |
, , , . , . . , , . .
, , .