The computer language has developed from the machine language to the high-level language generation from the machine language. It reflects the development of computer science and technology from complexity to simple (actually not simple). The more advanced computer language, the more abstract, the less the relationship between the low-level hardware, the more convenient it is. However, whether the computer language is high, it is an abstraction of the operating system layer, so we can always find the law behind the high-level language, that is: the code written by the senior language is just to describe people's needs, and these code should pass " Translator "translation into machine language forms can be implemented by machine computers. There are two ways to translate: First, the code is compiled, and the code generates a machine language code in advance, and then executes the operating system, such as the Delphi language, C language, etc .; Interpretation is performed, no matter the target program, such as a Basic language, scripting language, etc. The interpretation method is slow, and the computer hardware is relatively high.
Computer language defines the rules that describe people's needs, behind the language, the compiler or interpreter. The main job of the compiler or interpreter is the translation code, which has become the main channel for people with computer. In this case, in the case where the operating system is constant, various development tools are gone, but eventually generate computer executable code. So whether or the program written by using which computer language is to be judged, it is highly dependent on the language compiler or interpreter. Delphi's compiler is still currently the most advanced and most efficient compiler in the world.
From a high-level language, they are basically a service interface package provided by the operating system. Based on this, the language characteristics are joined, such as OOP, pointers, memory management mode, and more.
From the entire architecture of the Delphi language, we write the program either directly using the VCL, or call the API provided by the operating system, or use the COM service, or directly use the assembly language to complete our work.
VCL
Delphi's most core is the visual component library (VCL - Visual Component Library) and cross-platform component stock (CLX - ACOMPONENT LIBRARY for Cross-Platform), similar to Microsoft MFC, but its architecture is at least two to MFC. Three generations. Programming with Delphi You can choose VCL or you can start from the beginning without VCL. Suppose a program that is written and display "Hello World", if you don't have VCL, then you have to start with CreateWindow calling the API, but this is still to see your requirements. Here is just to explain the VCL with Delphi programming is not, such as a console program.
VCL is a powerful class library, which is the essence and crystallization of the Delphi language object-oriented characteristic. The class diagram structure is as follows:
This is a thumbnail class structure, but it is very representative. From the class diagram we can see that the VCL has only one root - TOBJCT, and each derived class has only one ancestor. This is the object-oriented characteristic of the Delphi language. All the original ancestors of all classes are Tobjcet, inherited methods are single inheritance. It should be noted:
l Although VCL design is very classic, don't be intimidated. To put it bluntly, he is a class library. It is a lot of classes with a certain relationship to complete a certain function class library, and these classes are either encapsulated Windows API, or call WindWS COM services, or use assembly direct operations RAM. As mentioned earlier, we can write programs that can be used with VCLs without VCL, indicating that VCL is not necessary. If necessary, we can inherit the extension of any of these classes to make the class that meets yourself. If we want to expand the TPanal class, the corresponding event (onMousenter / onmouseeleAve), such as the QQ panel is functional. u Create a new unit from [File] -> [New] -> [Unit].
The Used code is as follows, then saves the unit for MyPanelUnit.
Unit mypanelunit;
Interface
Uses Classes, Extctrls, Messages, Controls;
Type
TMouseActionEvent = Procedure (Sender: TOBJECT) OF Object;
TMYPANEL = Class (TPANEL)
Private
FONMOUSEENTER, FONMOUSELEAVE:
FouseAditionEvent;
// Intercept the mouse to enter the message
Procedure WMMouseEnter (Var Message:
TMESSAGE); Message Cm_MouseEnter;
// Intercept the mouse movement message
Procedure WmmouseLeave (Var Message:
TMESSAGE); Message Cm_MouseLeave;
Published
Property OnMouseEnter: TMouseActionEvent Read READ
FONMOUSEENTER WRITE FONMOUSEENTER;
Property OnMouseLeave: TMouseActionEvent Read
FONMOMSELEAVE WRITE FONMOUSELEAVE;
END;
/ (Note "R" in "REGISTER" must be capitalized, this is the only place to pay attention to the size in the Delphi language.
PROCEDURE register;
IMPLEMENTATION
{TMYPANEL}
PROCEDURE register;
Begin
/ / Register the component in the Delphi IDE, displayed on the panel "MyControl"
Registercomponents ('MyControl', [TMYPANEL]);
END;
Procedure TmyPanel.wmmouseEnter (Var Message: TMessage);
Begin
/ / Determine if there is code in the mouse, if there is an execution
IF assigned (fonmounteenter) THEN
FONMOUSEENTER (Self);
END;
Procedure TmyPanel.wmmouseLeave (Var Message: TMESSAGE);
Begin
/ / Determine if there is code in the mouse, if there is an execution
IF assigned (fonmouseLeave) THEN
FONMOMSELEAVE (Self);
END;
End.
u then click [Component] -> [Install Component ...], as shown below:
In the Unit File Name, we selected our unit myPanelUnit.pas, and other options default. Then click "OK", "Yes" in "Package DClusr.bpk Will BUILD THEN INSTALL, Continue?", Saved after the compilation is installed, so the TMYPANEL control is installed in Delphi. Scrolling Delphi Control Panel to the end, you will see the control page MyControl: U below, then create a new project, click [File] -> [New] -> [Application], drag the MyPanel in myControl page On Form, press the F11 key to switch to the Events page, as follows:
Compare with TPANEL, see if there are more onmouseenter and onmouseeleave events. Double-click onmouseEnter, write code as follows:
Procedure TFORM1.MYPANEL1MOUSEENTER (Sender: TOBJECT);
Begin
ShowMessage ('mouse enters MyPanel1');
END;
Then press F9 to run, move the mouse to myPanel1, look at what the result is.
It's so simple, we extended TPANEL, making it the ability to deal with the mouse to enter and remove events, so the VCL is not mysterious, anyone can rewrite the components (classes) inside, making it what you want.
l Delphi supports the inheritance of the interface. In a sense, multiple inherits are implemented, such as the definition of Tcomponent is as follows:
Tcomponent = Class (TPERSISTENT, IINTERFACE,
IinterfaceComponentReference)
l Don't create an instance of an abstract class. As long as one method is an abstract method, then this class is an abstract class. If TSTRINGS is defined as follows:
TSTREAM = Class (TOBJECT)
Private
...
protected
...
public
Function Read (var buffer; count: longint; virtual; abstentract;
Function Write (CONST BUFFER): Longint; Virtual; ABSTRACT
...
END;
As long as the Abstract keyword is an abstract method. There is no significance of creating an instance with an abstract class because read and write are not implemented. If the call will appear as an example.
(If you have not finished, please refer to Delphi back --- Beginner Reference 2 (2))
(If you need to reprint, please indicate the source and the author http://haitian.myrice.com)