类字段及类方法

1. 类字段, 使用class var 声明类字段。

Type
  TBall = class(TObject)
  class var
      shape: string;
      name: string;
  end;
View Code

2.类方法

  - 类方法声明以class开始,其余和一般方法没有任何区别。class关键字不能省略。

  - 类方法与普陀方法都可以通过对象来调用,但是类方法还可以直接通过类来调用。

  - 静态类方法

  

type
  T1 = class
    class function f2(var s: string): Integer; static
  end;

类静态方法没有引含的self参数,所以类静态方法不能引用引用任何的对象成员,但可以引用类字段和类方法。

原文地址:https://www.cnblogs.com/rexhu/p/5508266.html