type
  TFigure = class
  public
    class function Supports(Operation: string): Boolean; virtual;
    class procedure GetInfo(var Info: TFigureInfo); virtual;
    ...
  end;class procedure TFigure.GetInfo(var Info: TFigureInfo);
begin
  ...
end;类函数Supports和类过程GetInfo与一般的函数过程有什么区别?又有什么特殊用途?
"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 reference? 请举例说明。self又是什么意思?怎么使用?
"Self is useful for a variety of reasons. For example, a member identifier declared in a class type might be redeclared in the block of one of the class抯 methods. In this case, you can access the original member identifier as Self.Identifier."是什么意思?请举例说明。谢谢!

解决方案 »

  1.   

    Identifier 标识
    self.close;
      

  2.   

    类的SELF
      TFigure.classinfo
    对象的SELF
      @object
    如何求出对象所属类的SELF了?
     pinteger(@object)
      
      

  3.   

    类方法是在进行类申明的过程使用Class关键字进行限制的约束,是可以通过类和对象来进行调用的!类方法一般用来操作VMT中关于类本身的一些信息的存取,当然也有其他用途的!Self按照帮助中的意思就是指定一个对象,这个对象的特点就是在这个对象里面一个方法被调用,例如下面这个方法:
    procedure TForm1.OnCreate(Sender:TObject);
    begin
      Self.Position:=poDeskTop;
    end;
    这里Self指定一个对象,并且这个对象有一个特征,就是在对象中一个方法被调用,所以这里的这个对象就是指定了Form1,而Form1的属性Position被调用,同时Position的读写方法也被调用!
    这是对于一般的对象方法(即用来操作类实例的方法)而已。对于类方法,Self就相当于栈中对象实体的头四字节指针,直接指向VMT偏移地址为0的那个内存地址上,例如:
    ....
    type
    ....
      TTest=class 
      ....
        class procedure ClassMethodTest;
      ....
      end;
    ....
    procedure TTest.ClassMethodTest;
    begin
      ShowMessage(Self.ClassName);
    end;
    这里的Self就不是类TTest的任何实例了,而直接代表类TTest本身!类似于一个类引用类型。至于楼主最后那句话我也有点不太明白,等待其他人的见解!
      

  4.   

    刚才和OLD DM(gyb)讨论了你最后的一句话,呵呵,不好意思,我想错方向了!这个话的意思就是一个类中申明的数据成员有可能在类的方法中被重新申明,这里的重新实际上只是真对数据成员变量的名字而言,实际上申明的是另外一个变量!举个例子!
    type
      TTest=class
        private
          FA:Integer;
        public
          procedure SomeMethod(FA:Integer);  //注意,这里申明了一个FA,但与Private里面的FA是两个不同的变量,只不过是名字相同而已!
      end;
    ....
    procedure TTest.SomeMethod(FA:Integer);
    begin
      FA:=100;  //这个句子中的FA,编译器会认为这里是SomeMethod参数列表中的FA
                //如果这里要对类的私有数据成员FA进行操作,就要使用Self.FA,而不能单独用一个FA!
    end;---------------------------------------------------------------------------Self is useful for a variety of reasons. For example, a member identifier declared in a class type might be redeclared in the block of one of the class's methods
      

  5.   

    procedure TTest.SomeMethod(FA:Integer);
    begin
      FA:=100;  //这个句子中的FA,编译器会认为这里是SomeMethod参数列表中的FA
                //如果这里要对类的私有数据成员FA进行操作,就要使用Self.FA,而不能单独用一个FA!很好理解最近声明原则。FA:Integer声明的近,所以用的是他而不是SELF.FA