Delphi- object-oriented

1, for the process
2, based on the object
3, object-oriented

  Abstract: The same thing drawn up process
  derived (inherited): programming inheritance refers to the relationship between class and class, called derived.
  Package: The storm drain unnecessary details hidden.
  Polymorphic: a class object exists in many forms

1  { * ----------------------------------------------- -------------------------------
 2    1, to create class
 3      class members
 4        properties: a member variable, field
 5        function: method , functions, procedures, routines
 . 6    2, create an object class
 . 7  
. 8    3, the lifetime of an object (an object created from the dying out)
 9        3.1 constructor
 10          3.1.1, to apply a memory space in memory, in order to achieve creating an object
 11          3.1.2, class initialization function members
 12        3.2, destroying the object
 13 is          3.2.1, Free;
 14          3.2.2, the destroy;
 15          3.2.3, FreeAndNil;
 16          3.2.4, nil (null null) ;
 17       3.3, Self // this class object represents
 18          3.3.1 resolve name conflicts
 . 19  
20 is    4, the concept of the Delphi unit
 21  ---------------------- -------------------------------------------------- ------- }

 

. 1  type 
2    TUser = class (TObject) // all classes that inherit TObject 
. 3    the FName: String ; // field 
. 4    Procedure SetName (the Name: String ); // declaration defined 
. 5    destructor  the Destroy (); the override ;    // destruction ( destruction keyword destructor) 
6    constructor Aaa (the Name: String );   // construction method definitions (create keywords constructor) 
7    End ;
 8  // call 
9  constructorTUser.Aaa (the Name: String );   // constructor 
10  the begin 
. 11    // Initialization 
12 is    Self.FName: = the Name;
 13 is  
14  End ;
 15  
16  destructor . TUser the Destroy ;    // method of destroying objects 
. 17  the begin 
18 is    // call the method of destroying objects of the parent class 
. 19    Writeln ( ' method of destroying objects call the parent class ' );
 20 is    Inherited ;
 21 is  End ;
 22 is  
23 is  Procedure TUser.SetName (the Name: String );
24  the begin 
25    Self.FName: = the Name;
 26 is  End ;
 27  var 
28    the User: TUser;
 29  the begin 
30    // by the constructor to create a class object 
31 is    the User: = TUser.Aaa ( ' AA ' );    / / 'AA' parameter passing 
32  //   the User: = TUser.Create; // a memory address space of the application (object generation) to the memory 
33 is  //   User.FName: = 'Bauer'; 
34 is    Writeln (User.FName);
 35  //   User.Free; // destroy the object (the object is released) :( call TUser.Destroy method) template method design pattern 
36    FreeAndNil (the User); // destroy the object
37   Readln;
38 end.

 

Guess you like

Origin www.cnblogs.com/rise-home/p/11975908.html