CLASS FUNCTION ...  FUNCTION
CLASS PROCEDURE     PROCEDURE上面是对比的语句,一个说是作用在类,但我实在是不理解其中意思,有哪位大侠帮帮忙,不胜感激,
最好能用例子加以说明,谢谢了.

解决方案 »

  1.   

    CLASS FUNCTION ...  FUNCTION
    CLASS PROCEDURE     PROCEDURE统称为类方法,最典型的就是那些TXXX.ClassName,以及构造器TXXX.Create;Delphi帮助内容如下: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.
      

  2.   

    class function():boolean;
    class procedure();
    采用这种定义方式的方法通称为类方法; function():boolean;
     procedure();
    采用这种定义方式的方法通称为普通方法;类方法与普通方法有相同点与不同点:
      相同点:都是类方法,都可以通过类对象调用;
      不同点:类方法是一种操作类的方法,也就是说不需创建类的实例就可以用类方法来操作类,
              如类构造方法的应用(常用的模式窗体应用方式):
                   with Tfrom.create(self) do
                       try
                          showmodal;
                       finally
                          free;
                       end;
              而普通方法一定要在类的实例已创建的情况下才能调用,否则会报内存访问错!
      

  3.   

    //----------更正^_^
    class function():boolean;
    class procedure();
    采用这种定义方式的方法通称为类方法; function():boolean;
     procedure();
    采用这种定义方式的方法通称为普通方法;类方法与普通方法有相同点与不同点:
      相同点:都是类拥有的方法,可以完成相应的操作;
      不同点:类方法是一种操作类的方法,也就是说不需创建类的实例就可以用类方法来操作类,
              如类构造方法的应用(常用的模式窗体应用方式):
                   with Tfrom.create(self) do
                       try
                          showmodal;
                       finally
                          free;
                       end;
              而普通方法一定要在类的实例已创建的情况下才能调用,否则会报内存访问错!
      

  4.   

    带class的是静态方法
    同java中的static
    可以直接用类名访问,无须创建实例比如静态成员用来记录实例的个数