Delphi.NET internal implementation analysis (3.1)
2. Borland.delphi.system2.1.
Introduction
Tradition
Delphi
The default is included when compiling
SYSTEM
Similar to the unit,
Delphi.net
The program is protected by default when compiling
Borland.delphi.system
Unit, and this unit focuses on the definitions of the class and functions of many basic foundations.
versus
Delphi
Different, current
Delphi.net
Preview,
Borland.delphi.system
Also just included
Relatively basic function, such as
TOBJECT
Class and its related auxiliary functions, as well as some basic functions, especially many underlined
The prefix function is simply consolidated by the compiler level, such as the standard input and output function.
Writeln
And string processing functions, etc.
Let's take a little to analyze this most basic unit:
Borland.delphi.system
.
2.2.
Metacity
The development process of language is the gradual improvement of the abstract level of the problem domain. in
Delphi
,
C #
as well as
Java
These ones
Among the modern language, a very important feature is
RTTI
Support for runtime type information, and support will become more complete.
Delphi
One example in this regard is the application of the concept of the classification, and is used to further abstract the information of the class.
Regarding the concept and use of the yuan, there is a large number of books, and there is no more to say, let's take a look.
In traditional
Delphi
of
Object Pascal
In the language, the category is actually actually actually
VMT (Virtual Method Table
False method
)
,in
SYSTEM
It can be seen in detail in the definition of the unit.
// ---------------------------------------- System.Pas - {Virtual method table entries} vmtSelfPtr = -76; vmtIntfTable = -72; vmtAutoTable = -68; vmtInitTable = -64; vmtTypeInfo = -60; vmtFieldTable = -56; vmtMethodTable = -52; vmtDynamicTable = -48; vmtClassName = -44; vmtInstanceSize = -40; vmtParent = -36; vmtSafeCallException = -32 deprecated;. // do not use these constants vmtAfterConstruction = -28 deprecated; // use VMTOFFSET in asm code instead vmtBeforeDestruction = -24 deprecated; vmtDispatch = -20 deprecated; VMTDefaultHandler = -16 Deprecated; vmtnewinstance = -12 deprecated; vmtfreeinstance = -8 Deprecated; vmtdestroy = -4 deprecated; // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------- System.Pas - The first double word of the normal object is to point to its class.
VMT
The pointer to associate objects, classes, and categories.
This one
VMT
Form
Delphi
The core of the medium class is located, and most of the information can be acquired at runtime.
For example
VMT
One has a
Vmtselfptr
The pointer refers to
VMT
Head, we can use this feature to judge one
Whether the pointer points to whether it is a valid object or class.
JCL
There are code in the project as follows.
//----------------------------------------Jclsysutils.pas --function isclass (Address: Pointer): Boolean; assembler; asm CMP Address, Address.vmtSelfPtr JNZ @False MOV Result, True JMP @ Exit @ False: MOV Result, False @ Exit: end; function IsObject (Address: Pointer): Boolean; assembler ASM / / OR ISCLASS (Pointer (address ^)); MOV EAX, [Address] CMP EAX, Eax.Vmtselfptr jnz @false Mov Result, True JMP @ EXIT @ False: Mov Result, False @ EXIT: END; // ---------------------------------------- JCLSYSUTILS.PAS - through
VMT
Other fields can complete more wonderful features, such as
D6
Start
SOAP
Support in implementation,
Be through
VMT
Dynamic check table
SOAP
Function call to
Delphi
The function call for the interface is forwarded.
In
Delphi.net
Zhong, because
Borland
Unable to control the organization mode in memory, thus only
By mentioned above
Class Helper
Patch way, let
CLR
of
Bcl
of
System.Object
Use
Look like
TOBJECT
. This can indeed provide source code level compatibility to a large extent, but
JClsysUtils
Such
Hacker
The code is powerless.
:)