Delphi uses the object-oriented development idea, so when using Delphi as a development tool, Class and objects are particularly important!
The explicit definition of Class is: summarized for a class of things with the same features. As a very abstract concept, we can understand this word of the class: the students in the school, although everyone will have different situations, there are primary school students, middle school students, college students, men, girls, but they have A common point is in the stage of study. We can summarize them as "student class", and every student is the object of student class (one thing to explain, in many books, there is an entity or instance, here the entity or examples are mentioned ).
The attributes of the class refer to the static characteristics of the class. As the "student class" mentioned above, we say that he has the characteristics of gender, age, student number, class, school name, various examination results, etc. It is student class attribute.
The method of the class is the dynamic characteristics of this class, that is, the react that is made when the class is received, such as the student's class is a method of the student class, and the trigger of this method is the class bell ring An occurrence of a message.
The huge role of classes is also reflected in its unlimited inheritance. As the class mentioned above, we are divided into education, it is not difficult to see, you can also divide college students, middle school students, primary school students, and they are more specific, and their attributes of students have everything more than students. One has. In other words, they are inherited from the students, and they are more accurately divided on the basis of the student class. Here, students have an example as a child, college class, middle school students, primary school class, etc. Of course, there are more abstract classes above the students. For example, human beings are induced by human characteristics, and students are more specific than humans, in this place, human beings as parent class, and students as subclasses. As you can see here, we can define a class suitable for us and don't need every property, and the method can be written as long as the simple inheritance of the parent class. (Generally, the derived is the statement of the parent class: the parent class derived subclass.
VCL class library
Delphi's object-oriented foundation is class, to truly understand and improve Delphi's knowledge level, we have a big need to figure out that Delphi provides us with VCL (class library).
The hierarchical structure of Delphi is as follows:
As we can see from the figure, TOBJECT is a ancestral class in the Delphi system, and every class is his word class. According to the above level, we can see the inheritance and derived of each class in Delphi, which is very necessary to use the custom class. The following main items are introduced:
TPERSISTENT class:
It is derived from TOBJECT ancestors. It should be noted that both TPERSISTENT members can stream operation (transfer data to data stream)
Common methods:
Assign () A component assigns another component to yourself;
AssignTo () is in contrast to Assign (), which is privately defined in TPERSISTENT, and the derived class must implement his definition;
Tcomponent class
Directively derived by the TPERSISTENT class, its object: The property can be controlled by Object Inspector during design, and can have its components.
Tcomponent class can be seated and non-visual components such as TButton and Tmenu
Tcomponent is often used attributes:
Owner: Set or read component owners;
CompeNentCount: Read or set the number of components;
ComponentIndex: Read the location in its owner list (starting from 0);
Components: He is an array, contains its own component list (starting from 0); Name: Setting and reading component name;
Tcomponent common method
CREATE: Constructively;
DESTROY: Release the object;
GetParentComponent: Nothing to get the parent component, return NIL;
Hasparent: Judging whether the component has a parent component;
InsertComponent: Increases a component, which is owned by the components that call the method;
RemoveComponent: Delete a component you own;
FindComponent (str: string): Find components based on the component name given;
TControl class
Application: Generally used in visual components
Its attribute includes its own location information, size information, appearance attribute, etc., such as:
Top, Left, Width, Height, Visible, Enable, Text, CAPTION, etc .;
It introduces standard events such as:
Onclick, Ondblclick, OnMouseDown, Onmousemove, etc.
It should be noted that in Delphi, its derived class cannot be created, which can only be derived from the derived TWINCONTROL and TGRAPHICCONTROL it already exists;
TwinControl class
TwinControl class: Standard window control is derived from it;
Its object has a window handle (pointer to the object), which can accept the input focus, which can become the parent of other controls;
In application development, generally use TWINCONTROL derived classes;
The common attribute of the TwinControl class:
Brush: Used to draw the shape of the control;
Controls: All subcipes containing controls (value of one array);
ControlCount: The number of reads and sub-controls;
Handle: Read the handle of the TwinControl class object;
SHOWING: Set or read the object is visible;
TabStop: Set if the user can move the focus with the Tab key;
Taborder: Set the serial number (starting from 0) in its parent list;
TGRAPHICCONTROL class
This type of control has no window handle, cannot receive input focus, and cannot be the father of other controls;
TCOSTOMCONTROL class:
Its derived class is often used as a base class for custom controls.