码迷,mamicode.com
首页 > 其他好文 > 详细

类字段及类方法

时间:2016-05-19 13:11:29      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

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参数,所以类静态方法不能引用引用任何的对象成员,但可以引用类字段和类方法。

类字段及类方法

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!