There are many ways to declare a new class type:
TMyClass1 = TObject;TMyClass2 = type TObject开发者_如何学编程;TMyClass3 = class end;TMyClass4 = class(TObject);TMyClass5 = class(TObject) end;
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.
Are there any differences?
TMyClass1is just an alias - a different name forTObjectTMyClass2is 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.Pointerto create a handle type or something (see e.g. how this is used in Windows.pas).TMyClass3is a class, implicitly descending fromTObject, with no new members.TMyClass4is 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 forExceptiondescendantsTMyClass5is a class, explicitly descending fromTObject, with no new members. TheTObjectin the declaration is redundant, but it doesn't harm anything to make it explicit.
加载中,请稍侯......
精彩评论