类声明之间的区别 [英] Differences between class declarations
本文介绍了类声明之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有许多方法可以声明一个新的类类型:
There are many ways to declare a new class type:
-
TMyClass1 = TObject;
-
TMyClass2 = type TObject;
-
= class end;
-
TMyClass4 = class(TObject);
-
TMyClass5 = class(TObject)end;
TMyClass1 = TObject;
TMyClass2 = type TObject;
TMyClass3 = class end;
TMyClass4 = class(TObject);
TMyClass5 = class(TObject) end;
类3,4和5是 TObject
的后代,但不清楚1和2是如何不同的,3,4和5之间的区别是什么。
It's my understanding that class 3, 4 and 5 are descendants of TObject
, but it's not clear how 1 and 2 differ, and what the differences between 3,4 and 5 are.
有任何差异吗?
推荐答案
- code> TMyClass1 只是一个别名 -
TObject
的不同名称 -
TMyClass2
是TObject
(我们称之为type'd types)的强类型化别名;它是非常不寻常的使用这个与类,虽然,通常你会使用这个与例如。Pointer
创建一个句柄类型或某事(例如,如何在Windows.pas中使用它)。 -
TMyClass3
是一个类,隐含地从TObject
下降,没有新成员。 -
TMyClass4
是一个类,显式地从TObject
下降,没有新成员,使用简洁的语法。通常用于标记类,其中类本身的唯一性是有趣的事情 - 通常用于异常
后代 -
TMyClass5
是一个类,显式地从TObject
下降,没有新成员。该声明中的TObject
是多余的,但它不会对任何内容造成明显的损害。 TMyClass1
is just an alias - a different name forTObject
TMyClass2
is a strongly typed alias forTObject
(we call them "type'd types"); it's very unusual to use this with classes, though, normally you'd use this with e.g.Pointer
to create a handle type or something (see e.g. how this is used in Windows.pas).TMyClass3
is a class, implicitly descending fromTObject
, with no new members.TMyClass4
is a class, explicitly descending fromTObject
, with no new members, using the concise syntax. More normally, this is used for marker classes, where the uniqueness of the class itself is the interesting thing - often used forException
descendantsTMyClass5
is a class, explicitly descending fromTObject
, with no new members. TheTObject
in the declaration is redundant, but it doesn't harm anything to make it explicit.
这篇关于类声明之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文