TClass = class of TObject;什么意思?我看不懂。(50分)

  • 主题发起人 主题发起人 w8u
  • 开始时间 开始时间
W

w8u

Unregistered / Unconfirmed
GUEST, unregistred user!
我在帮助里看到了这个,但是不知道什么意思。
 
呵呵,你在哪里看到这个东东?
既然现在你还看不懂就先放着,以后再看嘛。

 
就是当然你定义一个类如:
TYourClass=TClass;等价于TYourClass=class(TObject).
 
类类型
具体含义看看Delphi中的帮助

或者看看Application.CreateForm的源代码就能理解类类型的意义了。
 
TObject是所有类的祖先,这里的TClass你可以用你的类来替换.因为它可以与任何类相容。
 
类引用。
 
TObject是所有類的祖先﹐如果你不用class(TObject),而只用class﹐實際上也是默認的
class(TObject)﹐所以class=class(TObject)。任何類都繼承自TObject.
 
别上dongberlin的贼当。
那时一个类引用。TClass = class of TObject就表示TClass是TObject或它子类的一个
变量。他表示的是类,而不是类的实例。
比如说
T1 = class of T0;
T2 = class(T0);
...
...
...
procedure *********
var
a: T2;
b: T1;
begin
b := T2; //b表示T1这个类或它的子类,而不是T1或T1子类的实例
a := b.create;
end;
 
是类引用,可以引用类:下面是帮助中的一段:
Sometimes operations are performed on a class itself, rather than on instances
of a class (that is, objects). This happens, for example, when you call a
constructor method using a class reference. You can always refer to a specific
class using its name, but at times it is necessary to declare variables or
parameters that take classes as values, and in these situations you need
class-reference types.
 
接受答案了.
 
后退
顶部