第一节 TObject原子 TObject是什么? 是Object Pascal语言体系结构的基本核心,也是各种VCL控件的起源。我们可以认为,TObject是构成DELPHI应用程序的原子之一,当然,他们又是由基本Pascal语法元素等更细微的粒子构成。 说TObject是DELPHI程序的原子,是因为TObject是DELPHI编译器内部支持的。所有的对象类都是从TObject派生的,即使你并未指定TObject为祖先类。TObject被定义在System单元,它是系统的一部分。在System.pas单元的开头,有这样的注释文本: { Predefined constants, types, procedures, } { and functions (such as True, Integer, or } { Writeln) do not have actual declarations.} { Instead they are built into the compiler } { and are treated as if they were declared } { at the beginning of the System unit. } 它的意思说,这一单元包含预定义的常量、类型、过程和函数(诸如:Ture、Integer或Writeln),它们并没有实际的声明,而是编译器内置的,并在编译的开始就被认为是已经声明的定义。你可以将Classes.pas或Windows.pas等其他源程序文件加入你的项目文件中进行编译和调试其源代码,但你绝对无法将System.pas源程序文件加入到你的项目文件中进行编译!DELPHI将报告重复定义System的编译错误! 因此,TObject是编译器内部提供的定义,对于我们使用DELPHI开发程序的人来说,TObject是原子性的东西。 TObject在System单元中的定义是这样的: TObject = class constructor Create; procedure Free; class function InitInstance(Instance: Pointer): TObject; procedure CleanupInstance; function ClassType: TClass; class function ClassName: ShortString; class function ClassNameIs(const Name: string): Boolean; class function ClassParent: TClass; class function ClassInfo: Pointer; class function InstanceSize: Longint; class function InheritsFrom(AClass: TClass): Boolean; class function MethodAddress(const Name: ShortString): Pointer; class function MethodName(Address: Pointer): ShortString; function FieldAddress(const Name: ShortString): Pointer; function GetInterface(const IID: TGUID; out Obj): Boolean; class function GetInterfaceEntry(const IID: TGUID): PInterfaceEntry; class function GetInterfaceTable: PInterfaceTable; 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; virtual; procedure FreeInstance; virtual; destructor Destroy; virtual; end;