4.4.1 module entry code
The compiler generates module entry code for each Delphi module (executable program, dynamic link library, or package. The entry code of a program or module of the same type is the same.
The entry code generated by the compiler for executable program. EXE is:
 
Project1.dpr. 9: descriebp0044ca99 8bec mov EBP, %83c4f0 add ESP,-$ %mov eax, $0044c8b8 // input unit initialization table address 0044caa3 e80080fbff cal10initexe // call module initialization routine
 
The entry code generated for the dynamic link library (. dll) is:
 
Project2.dpr. 19: Pushed pushed 8bec mov EBP, esp00b81fd7 83c4c4add ESP,-$ 3c00b81fda b85c1fb800 mov eax, $ 00b81f5c // input unit initialization table address 00b81fdp complete call initlib // call module initialization routine
 
The entry code generated for the package (. BPL) is:
 
Packagel. dpk.33: end, // The initialization routine of the jump module. It is a short jump to 04a512b0 e9c3feffff imp einitpkg.
 
Besides the package, the entry code is mainly used to input the address of the unit initialization table. All subsequent initialization work is completed by the module initialization routine in system. Pas. These routines are:
 
//define in SysInit. pasprocedure _InitLib;procedure _InitExe(InitTable: Pointer);function InitPkg(Hinst: Integer; Reason: Integer;Resvd: pointer): LongBool; stdcall;
 
 
4.4.2 procedure for executing a program determined by the compiler 
The compiler always generates the binary file of the project according to the fixed process and code. For example, a simple project:
 
Drogram GuiProg;uses    Dialogs;begin    ShowMessage(‘ Test‘);end.
 
The compiled code is:
 
GuiProg. dpr.4:begin00451F5C 55push     ebp00451F5D 8BEC      mov ebp, esp00451F5F 83C4F0     add esp,-$1000451F62 B8841D4500    mov eax,$00451d8400451F67 E8F43CFBFF    ca11 eInitExeGuiProg. dpr.5:ShowMessage(‘ Test‘);00451F6C B8841F4500   mov eax,$00451f8400451F71 E8D2FBFFFF    call ShowMessageGuiprog.dpr.6:end.00451F76 E8E11DFBFF   call eHalt0
 
The assembly code above is executed sequentially. The Compiler adds a line of "call" at the end of the process.
@ Halt0 ". Delphi does not intentionally prepare the final code for the module or specify the address of the final code. It only needs to compile in this way.
For executable programs (. (. DPA) begin .. the code added between the end determines all its functions, while the compiler only sets. DPR file according..
Other types of files are inconsistent with executable programs. In the next chapter "basic implementation for Windows development", we will detail all the module initialization and termination routines and their different execution processes.
 
4.4 module initialization and Termination