类函数\类过程.   它们是直接操作在类上面(没有实例化的对象)

下面是Delphi    Help    的描述   
    
   A class method is a method (other than a constructor) that operates on classes instead of objects. The definition of a class method must begin with the reserved word 
   class. For example,

type   
    TFigure = class   
    public   
     class function Supports(Operation: string): Boolean; virtual;   
     class procedure GetInfo(var Info: TFigureInfo); virtual;   
     ...   
    end;

The defining declaration of a class method must also begin with class. For example,

class procedure TFigure.GetInfo(var Info: TFigureInfo);   
   begin   
    ...   
   end;

In the defining declaration of a class method, the identifier Self represents the class where the method is called (which could be a descendant of the class in which it is defined). If the method is called in the class C, then Self is of the type class of C. Thus you cannot use Self to access fields, properties, and normal (object) methods, but you can use it to call constructors and other class methods.

A class method can be called through a class reference or an object reference. When it is called through an object reference, the class of the object becomes the value of Self.

类方法(Class methods)是一类特殊的方法,它们在声明时要以 class 开头:
    type
      TFigure = class
     public
     ...
   class procedure GetInfo(var Info: TFigureInfo); virtual;
       ...
     end;
  实现时也以 class 开头:
 class procedure TFigure.GetInfo(var Info: TFigureInfo); 
 begin
  ...
  end;
  乍一看好象平时没有遇到过这个东东,好象这个东东也没有什么大作用,其实不然。比如我们有时为输入密码或其他常用数据专门做一个 Form,但由于其代码都在 Form 定义的 unit 里面,所以在使用时仅仅需要几行代码,比如:
    with TfrmPassword.Create(nil) do
    try
  ShowModal;
 finally
 Free;
 end;
    虽然这样的代码已经很简洁,但如果写多了还是很讨厌的。利用类方法可以使其更简洁:
    TfrmPassword = class(TForm) 
    ...  
    public {Public declarations }  
    class function Execute: TModalResult;  
    end; 
    ...
 class function TfrmPassword.Execute: TModalResult; 
 begin
  with TfrmPassword.Create(nil) do 
     try
       Result :=ShowModal; 
     finally
      Release; //注意此处必须为release不能为free! 
     end; 
    end; 
 然后只用一行 TfrmPassword.Execute; 即可直接完成调用!

转载于:https://www.cnblogs.com/lzj1981/archive/2013/04/28/3049419.html

class function或class procedure是什么意思相关推荐

  1. MySQL This function has none of DETERMINISTIC, NO SQL...错误1418 的原因分析及解决方法

    原因分析: 因为CREATE PROCEDURE, CREATE FUNCTION, ALTER PROCEDURE,ALTER FUNCTION,CALL, DROP PROCEDURE, DROP ...

  2. postgresql 11 store procedure 初探之一

    os: centos 7.4 db: postgresql 11.5 postgresql 11 之前的函数(function)和存储过程(procedure)为同义词,语法如下: CREATE [O ...

  3. ORA-4031错误深入解析

    报ORA-4031错误时,我们通常可以根据Oracle无法分配多少字节的内存,来判断共享池碎片的严重程度,以下是4031错误官方的解释: [oracle@guoyj ~]$ oerr ORA 4031 ...

  4. 自己写的一个测试函数执行效率的单元(test on Delphi 7)

    运用了一点技巧来实现对函数进行效率测试 使用方法: uses   Profile; ....... function TForm1.Func1():string; begin     TFunctio ...

  5. 利用属性封装复杂的选项

    1.考虑这样一个场景. 我们的程序中有一个"选项"窗口,这个窗口包含很多选项.其中有一个选项是单选类型的,用户可以从N个选项值中选择一个. 我们需要在用户单击"确定&qu ...

  6. Delphi中的容器类(二)

    TStrings类 出于效率的考虑,Delphi并没有象C++和Java那样将字符串定义为类,因此TList本身不能直接存储字符串,而字符串列表又是使用非常广泛的,为此Borland提供了TStrin ...

  7. 用delphi创建服务程式

    视窗系统 2000/XP和2003等支持一种叫做"服务程式"的东西.程式作为服务启动有以下几个好处: (1)不用登陆进系统即可运行. (2)具有SYSTEM特权.所以你在进程管理器 ...

  8. mysql 2014_mysql错误之2014

    error:2014 Commands out of sync; you can't run this command now 这个错误号我也真是醉了. 一直纠结于为什么存储过程执行完,commit操 ...

  9. Delphi中的线程类

    Delphi中有一个线程类TThread是用来实现多线程编程的,这个绝大多数Delphi书藉都有说到,但基本上都是对TThread类的几个成员作一简单介绍,再说明一下Execute的实现和Synchr ...

最新文章

  1. kafka消息会不会丢失
  2. classpath详解
  3. 线程锁与避免线程锁 线程锁检测
  4. 【微信小程序】scroll-view与Page下拉冲突
  5. 看懂类图——UML类图基础
  6. Tomcat打包时多项目共享jar和精确指定jar版本
  7. youcans 的 OpenCV 学习课—1.安装与环境配置
  8. 阿帕奇与php整合,整合apache和php
  9. 微软牛津计划介绍——屌爆了的自然数据处理解决方案(人脸/语音识别,计算机视觉与语言理解)
  10. 并发与计算机体系结构
  11. iOS (导航条)navBar 透明
  12. Chrome开发者工具对于异常请求不显示Response内容
  13. 【历史上的今天】8 月 29 日:Wolfram 语言之父、“新”科学家 Stephen Wolfram 的诞生
  14. 360云服务器合作,360云主机速度(云服务器)
  15. vs2015下,使用人脸检测算法对FDDB数据集进行测评
  16. JavaScript编写答题评分功能页面
  17. 多米诺DP(双向背包)算法总结
  18. opencv漫水填充算法floodfill
  19. could和may区别请求_英语教学:外教这样区分can,may,could
  20. 「Adobe国际认证」运用“对象选择”工具,在PS中快速建立选区

热门文章

  1. 2022-2028年中国铁路行业投资分析及前景预测报告(全卷)
  2. 2022-2028年中国塑料合成革的制造行业市场全景评估及发展趋势研究报告
  3. 3分钟4 步快速带你在win10电脑装上openCV3.4 (python使用)
  4. 使用阿里云服务器安装docker,并用nginx示例
  5. Docker安装Nextcloud
  6. 操作系统学习笔记 第二章:进程管理(王道考研)
  7. 初具雏形的UL标准侧重于自主车辆的安全性
  8. 2021年大数据Spark(十一):应用开发基于IDEA集成环境
  9. Dockerfile的详解
  10. 谷歌不更新android studio,彻底迈向64位:谷歌宣布 Android Studio 将停止 32 位版本更新...