从system.pas看Delphi XE10的IDE编译逻辑

从system.pas看Delphi XE10的IDE编译逻辑

        Delphi XE10的IDE,作为编译型语言pascal的最主要的集成开发环境,其编译的程序代码在运行时,本质是在执行其编译时就已经解释(Compile)好并将解释好的二进制代码链接(Build)到可执行的DLL或EXE,而其编译过程(或者说其解释和链接)的起点,则在原则单元system.pas,delphi XE10将其列入源码的运行时刻库RTL的系统sys目录下:source\rtl\sys。现对system.pas的逻辑亦即delphi XE10的IDE编译逻辑,诠释如下

        以下简要以序号的序数,描述delphi XE10的IDE编译逻辑的过程:

001、描述代码的类别PUREPASCAL和X86ASMRTL

{$IF defined(CPUX86) and defined(ASSEMBLER)}  
  {$DEFINE X86ASMRTL}   //:如果编译环境是X86或汇编,则调用X86或ASM的运行时刻库编译(比如,Win32 API、汇编ASM)
{$ELSE}
  {$DEFINE PUREPASCAL}   //:否则,使用纯pascal语言
{$ENDIF}

002、描述栈、表、PC映射、MACOS及Linux等的异常全局处理标识符

{$IFNDEF PC_MAPPED_EXCEPTIONS}
  {$IF defined(ANDROID)}
    {$DEFINE ZCX_BASED_EXCEPTIONS}
  {$ELSEIF defined(MACOS)}
    {$IF defined(CPUARM32)}
      {$DEFINE SJLJ_BASED_EXCEPTIONS}
    {$ELSEIF defined(CPUARM64)}
      {$DEFINE ZCX_BASED_EXCEPTIONS_MACOS}
    {$ELSEIF defined(CPUX64)}
      {$DEFINE ZCX_BASED_EXCEPTIONS_MACOS}
    {$ENDIF}
  {$ELSEIF defined(MSWINDOWS)}
    {$IFDEF EXTERNALLINKER}
      {$DEFINE ZCX_BASED_EXCEPTIONS}
    {$ELSE}
      {$IF defined(CPUX86)}
        {$DEFINE STACK_BASED_EXCEPTIONS}
      {$ELSEIF defined(CPUX64)}
        {$DEFINE TABLE_BASED_EXCEPTIONS}
      {$ELSE}
        {$MESSAGE ERROR 'Unknown platform'}
      {$ENDIF}
    {$ENDIF !EXTERNALLINKER}
  {$ELSEIF defined(LINUX)}
    {$IFDEF EXTERNALLINKER}
      {$DEFINE ZCX_BASED_EXCEPTIONS}
    {$ELSE}
      {$DEFINE PC_MAPPED_EXCEPTIONS}
    {$ENDIF}
  {$ELSE}
    {$MESSAGE ERROR 'Unknown platform'}
  {$ENDIF}
{$ENDIF !PC_MAPPED_EXCEPTIONS}

003、对扩展的六类不同位长的字节数组(10BYTES、16BYTES、12BYTES、10BYTES、8BYTES)及算术运算(ARITH)的环境和架构的全局处理标识符的约定

EXTENDEDHAS10BYTES
EXTENDEDIS16BYTES         比如: {$IF SizeOf(Extended) = 16}
EXTENDEDIS12BYTES
EXTENDEDIS10BYTES
EXTENDEDIS8BYTES
如果是纯pascal,则:{$DEFINE 下述}
ARITH_PUREPASCAL_EXT80 比如:{$IFDEF CPUX86}
ARITH_PUREPASCAL_EXT64      {$IFDEF CPUX64}
ARITH_USE_LIBM              {$IFDEF LINUX}
ARITH_USE_LIBM              {$IFDEF CPUARM}
如果是非纯pascal,则:{$DEFINE 下述}
ARITH_X32_FPU          比如:{$IFDEF CPUX86 and ASSEMBLER}
ARITH_PUREPASCAL_EXT80
ARITH_USE_LIBM
ARITH_X64_SSE
ARITH_PUREPASCAL_EXT64
//:以上具体约定细节,详见其源码103-176行次   

004、对编译器版本(运行时刻库版本级别)的描述约定

内部使用:RTLVersion和Embedded,比如:{$IF RTLVersion >= 16.2} ... {$ENDIF}

const
  RTLVersion = 34.00;
{$HPPEMIT '#define RTLVersionC 3400'}

{$IF (Defined(NEXTGEN) or defined(ANDROID)) and Defined(EMBEDDED)}
  Embedded = True;
{$ENDIF}

外部引用:CompilerVersion,比如:{$IF CompilerVersion >= 34} //34 为 Delphi10.4,

005、约定代码的License的描述

const
  GPL = True;   //General Public License (GPL) :GNU组织进行管理

006、对.hpp/.obj的兼容描述

数据类型

Type

007、很有用的类型的别名的约定Useful alias types

type
  {$NODEFINE Int8} // We map 'Shortint' to 'Int8' for C++ above
  Int8    = ShortInt;
  Int16   = SmallInt;
  Int32   = Integer;
  IntPtr   = NativeInt;
  UInt8   = Byte;
  UInt16   = Word;
  UInt32   = Cardinal;
  UIntPtr = NativeUInt;
{$IFDEF MACOS} {mactypes.h}
  {$EXTERNALSYM UInt8}
  {$EXTERNALSYM UInt16}
  {$EXTERNALSYM UInt32}
{$ENDIF}
  Float32 = Single;
  Float64 = Double;

// 内部使用的别名Internal Aliases:

  {$IFDEF NEXTGEN}   //:如果定义了下一代
  _ShortStr = _ShortString;
  _AnsiStr = _AnsiString;
  _AnsiChr = _AnsiChar;
  _WideStr = _WideString;
  _PAnsiChr = _PAnsiChar;
  UTF8Char = _AnsiChar;
  PUTF8Char = _PAnsiChar;
  {$ELSE}
  _ShortStr = ShortString;
  _AnsiStr = AnsiString;
  _AnsiChr = AnsiChar;
  _WideStr = WideString;
  _PAnsiChr = PAnsiChar;
  UTF8Char = AnsiChar;
  PUTF8Char = PAnsiChar;
  {$ENDIF}
  MarshaledString = PWideChar;       //:编组或封装的字符串(即多字节字符串)
  MarshaledAString = _PAnsiChr;       //:编组或封装的字符(即多字节字符)
{$NODEFINE    MarshaledString   }   //弃用
{$NODEFINE    MarshaledAString }   //弃用
{$NODEFINE    _ShortStr    }   //弃用
{$NODEFINE    _WideStr     }   //弃用
{$NODEFINE    _AnsiStr     }   //弃用
{$NODEFINE    _AnsiChr     }   //弃用
{$NODEFINE    _PAnsiChr    }   //弃用

008、常量-变量类型的编码及序数约定

16进制常量标识符    16进制序数   10进制常量标识符   10进制序数

  varEmpty    = $0000; { vt_empty        0 }
  varNull     = $0001; { vt_null         1 }
  varSmallint = $0002; { vt_i2           2 }
  varInteger   = $0003; { vt_i4           3 }
  varSingle   = $0004; { vt_r4           4 }
  varDouble   = $0005; { vt_r8           5 }
  varCurrency = $0006; { vt_cy           6 }
  varDate     = $0007; { vt_date         7 }
  varOleStr   = $0008; { vt_bstr         8 }
  varDispatch = $0009; { vt_dispatch     9 }
  varError    = $000A; { vt_error       10 }
  varBoolean   = $000B; { vt_bool        11 }
  varVariant   = $000C; { vt_variant     12 }
  varUnknown   = $000D; { vt_unknown     13 }
//varDecimal   = $000E; { vt_decimal     14 } {UNSUPPORTED as of v6.x code base}
//varUndef0F   = $000F; { undefined      15 } {UNSUPPORTED per Microsoft}
  varShortInt = $0010; { vt_i1          16 }
  varByte     = $0011; { vt_ui1         17 }
  varWord     = $0012; { vt_ui2         18 }
  varLongWord = $0013   { vt_ui4         19 } {deprecated 'use varUInt32'} ;
  varUInt32   = $0013; { vt_ui4         19 }
  varInt64    = $0014; { vt_i8          20 }
  varUInt64   = $0015; { vt_ui8         21 }
  varRecord   = $0024; { VT_RECORD      36 }
{   if adding new items, update Variants' varLast, BaseTypeMap and OpTypeMap }

  varStrArg   = $0048; { vt_clsid        72 }
  varObject   = $0049; {                 73 }
  varUStrArg   = $004A; {                 74 }
  varString   = $0100; { Pascal string   256 } {not OLE compatible }
  varAny      = $0101; { Corba any      257 } {not OLE compatible }
  varUString   = $0102; { Unicode string 258 } {not OLE compatible }
  // custom types range from $110 (272) to $7FF (2047)

  varTypeMask = $0FFF;
  varArray    = $2000;
  varByRef    = $4000;

009、常量-TVarRec.VType values可变记录的变量类型值的编码及序数约定

  vtInteger       = 0;
  vtBoolean       = 1;
  vtChar          = 2;
  vtExtended      = 3;
  vtString        = 4{$IFDEF NEXTGEN} deprecated 'Type not supported' {$ENDIF NEXTGEN};
  vtPointer       = 5;
  vtPChar         = 6;
  vtObject        = 7;
  vtClass         = 8;
  vtWideChar      = 9;
  vtPWideChar     = 10;
  vtAnsiString    = 11;
  vtCurrency      = 12;
  vtVariant       = 13;
  vtInterface     = 14;
  vtWideString    = 15;
  vtInt64         = 16;
  vtUnicodeString = 17;

{$IFDEF AUTOREFCOUNT}
  vmtArcOffset    = 2 * SizeOf(Pointer);
{$ELSE}
  vmtArcOffset    = 0;
{$ENDIF}

{$IFDEF CPP_ABI_SUPPORT}
  CPP_ABI_ADJUST = 3 * SizeOf(Pointer);
{$ELSE !CPP_ABI_SUPPORT}
  CPP_ABI_ADJUST = 0;
{$ENDIF !CPP_ABI_SUPPORT}

010、常量-虚拟方法表入口Virtual method table entries

{$IF defined(CPU64BITS)}
  vmtSelfPtr           = -176 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtIntfTable         = -168 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtAutoTable         = -160 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtInitTable         = -152 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtTypeInfo          = -144 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtFieldTable        = -136 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtMethodTable       = -128 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtDynamicTable      = -120 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtClassName         = -112 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtInstanceSize      = -104 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtParent            = -96 - vmtArcOffset - CPP_ABI_ADJUST;
{$IFDEF AUTOREFCOUNT}
  vmtObjAddRef         = -104 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtObjRelease        = -96 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
{$ENDIF}
  vmtEquals            = -88 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtGetHashCode       = -80 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtToString          = -72 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtSafeCallException = -64 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtAfterConstruction = -56 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtBeforeDestruction = -48 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtDispatch          = -40 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtDefaultHandler    = -32 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtNewInstance       = -24 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtFreeInstance      = -16 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtDestroy           =   -8 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtQueryInterface    =   0 deprecated 'Use VMTOFFSET in asm code';
  vmtAddRef            =   8 deprecated 'Use VMTOFFSET in asm code';
  vmtRelease           = 16 deprecated 'Use VMTOFFSET in asm code';
  vmtCreateObject      = 24 deprecated 'Use VMTOFFSET in asm code';
{$ELSE !CPU64BITS}
  vmtSelfPtr           = -88 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtIntfTable         = -84 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtAutoTable         = -80 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtInitTable         = -76 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtTypeInfo          = -72 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtFieldTable        = -68 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtMethodTable       = -64 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtDynamicTable      = -60 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtClassName         = -56 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtInstanceSize      = -52 - vmtArcOffset - CPP_ABI_ADJUST;
  vmtParent            = -48 - vmtArcOffset - CPP_ABI_ADJUST;
{$IFDEF AUTOREFCOUNT}
  vmtObjAddRef         = -52 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtObjRelease        = -48 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
{$ENDIF}
  vmtEquals            = -44 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtGetHashCode       = -40 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtToString          = -36 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtSafeCallException = -32 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtAfterConstruction = -28 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtBeforeDestruction = -24 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtDispatch          = -20 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtDefaultHandler    = -16 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtNewInstance       = -12 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtFreeInstance      = -8 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';
  vmtDestroy           = -4 - CPP_ABI_ADJUST deprecated 'Use VMTOFFSET in asm code';

  vmtQueryInterface    = 0 deprecated 'Use VMTOFFSET in asm code';
  vmtAddRef            = 4 deprecated 'Use VMTOFFSET in asm code';
  vmtRelease           = 8 deprecated 'Use VMTOFFSET in asm code';
  vmtCreateObject      = 12 deprecated 'Use VMTOFFSET in asm code';
{$ENDIF !CPU64BITS}

011、常量-隐藏对象字段信息Hidden TObject field info

  hfFieldSize          = SizeOf(Pointer);
  hfMonitorOffset      = 0;

012、运行时类(Type)信息的可见性RTTI Visibility

type
  TVisibilityClasses = set of (vcPrivate, vcProtected, vcPublic, vcPublished);
const
  //这些常量表示编译器中内置的默认设置。对于类,这些设置通常从TObject继承
  DefaultMethodRttiVisibility = [vcPublic, vcPublished];     //:方法的可见性,需要(或继承后)公布Public或发布Published出来
  DefaultFieldRttiVisibility = [vcPrivate..vcPublished];        //:字段的可见性,私有或受保护或Public或Published,或继承后公布Public或发布Published出来
  DefaultPropertyRttiVisibility = [vcPublic, vcPublished];    //:属性的可见性,需要(或继承后)公布Public或发布Published出来

013、底级别的几个系统类

  TArray<T> = array of T;   // : 对泛型动态数组的描述方法约定

  TObject = class; // : 系统级别的对象SYSTEM_HPP_DEFINES_OBJECTS

  TClass = class of TObject;   // : TObject的别名: 系统级别的对象SYSTEM_HPP_DEFINES_OBJECTS

  HRESULT     // : 外部模块的整型表达的约定

  {$IFDEF LONGINT64}
  HRESULT = type Int32;
  {$EXTERNALSYM HRESULT}
  {$ELSEIF defined(EXTERNALLINKER)}
  HRESULT = type CppLongInt;
  {$EXTERNALSYM HRESULT} { long }
  {$ELSE}
  HRESULT = type LongInt;   { from wtypes.h }
  {$EXTERNALSYM HRESULT} {$OBJTYPENAME HRESULT 'Bl' 'Gl'} { long }
  {$ENDIF}

  TGUID全局唯一标识符的记录及其指针:

  PGUID = ^TGUID;
  TGUID = record
    D1: Cardinal;
    D2: Word;
    D3: Word;
    D4: array[0..7] of Byte;
    class operator Equal(const Left, Right: TGUID): Boolean; inline;
    class operator NotEqual(const Left, Right: TGUID): Boolean; inline;
    class function Empty: TGUID; static;
    class function Create(const Data; BigEndian: Boolean = False): TGUID; overload; static;
    class function Create(const Data: array of Byte; AStartIndex: Cardinal; BigEndian: Boolean = False): TGUID; overload; static;
    function IsEmpty: Boolean;
  end;

  TInterfaceEntry接口的入口的封装记录及其指针:

  PInterfaceEntry = ^TInterfaceEntry;
  TInterfaceEntry = packed record
    IID: TGUID;
    VTable: Pointer;
    IOffset: Integer;
    {$IF defined(CPU64BITS)}
    _Filler: UInt32;
    {$ENDIF}
    ImplGetter: NativeUInt;
  end;

  TInterfaceTable接口表的封装记录及其指针:

  PInterfaceTable = ^TInterfaceTable;
  TInterfaceTable = packed record
    EntryCount: Integer;
    {$IF defined(CPU64BITS)}
    _Filler: UInt32;
    {$ENDIF}
    Entries: array[0..9999{EntryCount - 1}] of TInterfaceEntry;
   {Intfs: array[0..EntryCount - 1] of PPTypeInfo;}
  end;

  TMethod方法(的代码及数据)记录及其指针:

  PMethod = ^TMethod;
  TMethod = record
    Code, Data: Pointer;
  public
    class operator Equal(const Left, Right: TMethod): Boolean; inline;
    class operator NotEqual(const Left, Right: TMethod): Boolean; inline;
    class operator GreaterThan(const Left, Right: TMethod): Boolean; inline;
    class operator GreaterThanOrEqual(const Left, Right: TMethod): Boolean; inline;
    class operator LessThan(const Left, Right: TMethod): Boolean; inline;
    class operator LessThanOrEqual(const Left, Right: TMethod): Boolean; inline;
  end;

消息及其传递机制:

TObject.Dispatch接受任何数据类型作为其消息参数。在对象的消息方法中,数据的前2个字节作为要搜索的消息id(MsgID)。TDispatchMessage是这样一种结构,其中包含消息id(MsgID)的字段。比如:

  TDispatchMessage = record
    MsgID: Word;
  end;

对象的祖先类(TObject)的描述:

  TObject = class
  public
    constructor Create;
    procedure Free;
    procedure DisposeOf; {$IFNDEF AUTOREFCOUNT} inline; {$ENDIF}
    class function InitInstance(Instance: Pointer): TObject {$IFDEF AUTOREFCOUNT} unsafe {$ENDIF};
    procedure CleanupInstance;
    function ClassType: TClass; inline;
    class function ClassName: string;
    class function ClassNameIs(const Name: string): Boolean;
    class function ClassParent: TClass;
    class function ClassInfo: Pointer; inline;
    class function InstanceSize: Integer; inline;
    class function InheritsFrom(AClass: TClass): Boolean;
    class function MethodAddress(const Name: _ShortStr): Pointer; overload;
    class function MethodAddress(const Name: string): Pointer; overload;
    class function MethodName(Address: Pointer): string;
    class function QualifiedClassName: string;
    function FieldAddress(const Name: _ShortStr): Pointer; overload;
    function FieldAddress(const Name: string): Pointer; overload;
    function GetInterface(const IID: TGUID; out Obj): Boolean;
    class function GetInterfaceEntry(const IID: TGUID): PInterfaceEntry;
    class function GetInterfaceTable: PInterfaceTable; inline;
    class function UnitName: string;
    class function UnitScope: string;
{$IFDEF AUTOREFCOUNT}
    function __ObjAddRef: Integer; virtual;
    function __ObjRelease: Integer; virtual;
{$ENDIF}
    function Equals(Obj: TObject): Boolean; virtual;
    function GetHashCode: Integer; virtual;
    function ToString: string; virtual;
    function SafeCallException(ExceptObject: TObject;
      ExceptAddr: Pointer): HResult; virtual;
    procedure AfterConstruction; virtual;
    procedure BeforeDestruction; virtual;
    procedure Dispatch(var Message); virtual;
    procedure DefaultHandler(var Message); virtual;
    class function NewInstance: TObject {$IFDEF AUTOREFCOUNT} unsafe {$ENDIF}; virtual;
    procedure FreeInstance; virtual;
{$IFDEF AUTOREFCOUNT}
  protected
{$ENDIF}
    destructor Destroy; virtual;

{$IFDEF CPP_ABI_SUPPORT}
    procedure CPP_ABI_1; virtual;
    procedure CPP_ABI_2; virtual;
    procedure CPP_ABI_3; virtual;
{$ENDIF !CPP_ABI_SUPPORT}

  protected
    function GetDisposed: Boolean; inline;
    procedure CheckDisposed; {$IFNDEF AUTOREFCOUNT} inline; {$ENDIF}

{$IFDEF AUTOREFCOUNT}
  private const
    objDestroyingFlag = Integer($80000000);
    objDisposedFlag = Integer($40000000);
  protected
                                                               
    [Volatile] FRefCount: Integer;
    class procedure __MarkDestroying(const Obj); static; inline;
    class function __SetDisposed(const Obj): Boolean; static; inline;
  public
    property RefCount: Integer read FRefCount;
{$ENDIF AUTOREFCOUNT}
    property Disposed: Boolean read GetDisposed;
  end;


类或对象的属性的基类(RTTI单元中)的描述:

  TCustomAttribute = class(TObject)
  end;

类或对象的其它几类继承属性的描述:

  WeakAttribute = class(TCustomAttribute);
  UnsafeAttribute = class(TCustomAttribute);
  RefAttribute = class(TCustomAttribute);
  VolatileAttribute = class(TCustomAttribute);
  StoredAttribute = class(TCustomAttribute);
  HPPGENAttribute = class(TCustomAttribute);

只能在类或对象的内部使用(比如设计时等)继承属性的描述:

HFAAttribute = class(TCustomAttribute);

AlignAttribute = class(TCustomAttribute);

014、就开始说线程啦:

{$IFDEF NEXTGEN}
  CheckForCyclesProc = procedure (const Obj: TObject);   //:线程内部的自旋匿名过程
{$ENDIF NEXTGEN}

{$IF Defined(MSWINDOWS)}
  TThreadID = LongWord;   //:识别线程的唯一标志:长字(无符号)
{$ENDIF}
{$IFDEF POSIX}
  TThreadID = NativeUInt;    //:识别线程的唯一标志:无符号整型
{$ENDIF}

  PPMonitor = ^PMonitor;
  PMonitor = ^TMonitor;
  TMonitor = record      //:实例化对象的线程安全监视器记录
  //......
  public
    class procedure SetSpinCount(const AObject: TObject; ASpinCount: Integer); static;
    class procedure Enter(const AObject: TObject); overload; static; inline;
    class function Enter(const AObject: TObject; Timeout: Cardinal): Boolean; overload; static;
    class procedure Exit(const AObject: TObject); overload; static;
    class function TryEnter(const AObject: TObject): Boolean; overload; static;
    class function Wait(const AObject: TObject; Timeout: Cardinal): Boolean; overload; static;
    class function Wait(const AObject, ALock: TObject; Timeout: Cardinal): Boolean; overload; static;
    class procedure Pulse(const AObject: TObject); overload; static;
    class procedure PulseAll(const AObject: TObject); overload; static;
    class property DefaultSpinCount: Integer read FDefaultSpinCount write SetDefaultSpinCount;
  end;

线程等待相关的无限大(Cardinal的序数的高位)的无符号常量整数:

const
  INFINITE = Cardinal($FFFFFFFF);       {$EXTERNALSYM INFINITE}

线程安全相关的几个重要方法:  

function MonitorEnter(const AObject: TObject; Timeout: Cardinal = INFINITE): Boolean; inline;
function MonitorTryEnter(const AObject: TObject): Boolean; inline;
procedure MonitorExit(const AObject: TObject); inline;
function MonitorWait(const AObject: TObject; Timeout: Cardinal): Boolean; inline; overload;
function MonitorWait(const AObject, ALock: TObject; Timeout: Cardinal): Boolean; inline; overload;
procedure MonitorPulse(const AObject: TObject); inline;
procedure MonitorPulseAll(const AObject: TObject); inline;
// Note: MemoryBarrier is now standard function.
//procedure MemoryBarrier;
procedure YieldProcessor; {$EXTERNALSYM YieldProcessor }  

// : 现在讲到第947行了 ,先休息休息,接下来又讲!


联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678