在delphi / objectpascal中 - “procedure somemethod()”之间的区别。和“类程序somemethod()” [英] In delphi/objectpascal - difference between "procedure somemethod()" and "class procedure somemethod()"
问题描述
我很难理解以下(类似)程序定义之间的区别。另外我想知道如何确定何时以及为何使用第二个定义。
#1 - 标准例行定义
I am having difficulties understanding the difference between the following (similar) procedure definitions. Also I'm wondering how to determine when and why to use the 2nd definition.
#1 - Standard routine definition
type
TFigure = class
public
function Supports(Operation: string): Boolean; virtual;
procedure GetInfo(var Info: TFigureInfo); virtual;
...
end;
#2 - 常规以关键字class开头
#2 - routine prefaced by the keyword "class"
type
TFigure = class
public
class function Supports(Operation: string): Boolean; virtual;
class procedure GetInfo(var Info: TFigureInfo); virtual;
...
end;
我的尝试:
我用Google搜索了这个主题,无法找到何时/为何使用class关键字的简单直接定义。
这两个例子在我的问题中取自Embarcadero网站 - 我刚刚删除了类,例如#1。我没有看到任何文档:具体的差异或何时/为什么以关键字class开头。
这已经困扰了我很长一段时间了,非常感谢任何澄清。
b 。
What I have tried:
I've googled this topic and cannot find a simple, direct definition of when/why to use the "class" keyword.
The 2 examples in my question were taken from the Embarcadero website - I just removed the "class" for example #1. I did not see any documentation re: the specific differences or when/why to preface with the keyword "class".
This has been bugging me for quite a while now and any clarification is greatly appreciated.
b.
推荐答案
没有class说明符的方法(过程/函数)是普通方法,它们是类的任何INSTANCE的一部分,而那些具有类的方法class说明符是类本身的方法,而不是类的INSTANCE。
The methods (procedures / functions) without the "class" specifier are normal methods that are a part of any INSTANCE of a class, whereas those with the "class" specifier are methods of the class itself, and not of an INSTANCE of the class.
这篇关于在delphi / objectpascal中 - “procedure somemethod()”之间的区别。和“类程序somemethod()”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!