The TObject
class, declared in the System unit, is the ultimate ancestor of all
other classes. TObject defines only a handful of methods, including a
basic constructor and destructor. In addition to TObject, the System
unit declares the class-reference
type TClass:
TClass
= class of TObject;
If the
declaration of a class type doesn’t specify an ancestor, the class inherits
directly from TObject. Thus
type
TMyClass = class
...
end;
is equivalent to
type
TMyClass = class(TObject)
...
end;
The latter form is recommended for readability.
TObject
TObject类声明于System单元中,它是其他所有类(严格地说,是绝大多数类)的最终祖先。TObject仅定义了一少部分方法,包括基本的构造器和析构器。除TObject外,System单元中还声明了类引用类型(class-reference)TClass:
TClass
= class of TObject;
如果在类类型的声明中没有指定其祖先,那么该类直接继承TObject 。因此,下面的声明
type
TMyClass = class
...
end;
等价于
type
TMyClass = class(TObject)
...
end;
推荐使用后一种形式,因为后者更具可读性。
TObject