请教一下,delphi的静态方法有什么用?

解决方案 »

  1.   

    Methods are by default static. When a static method is called, the declared (compile-time) type of the class or object variable used in the method call determines which implementation to activate. In the following example, the Draw methods are static.type
      TFigure = class
        procedure Draw;
      end;
      TRectangle = class(TFigure)
        procedure Draw;
      end;Given these declarations, the following code illustrates the effect of calling a static method. In the second call to Figure.Draw, the Figure variable references an object of class TRectangle, but the call invokes the implementation of Draw in TFigure, because the declared type of the 
    Figure variable is TFigure.var
      Figure: TFigure;
      Rectangle: TRectangle;
    begin
      Figure := TFigure.Create;
      Figure.Draw;  // calls TFigure.Draw
      Figure.Destroy;
      Figure := TRectangle.Create;
      Figure.Draw;  // calls TFigure.Draw
      TRectangle(Figure).Draw;  // calls TRectangle.Draw
      Figure.Destroy;
      Rectangle := TRectangle.Create;
      Rectangle.Draw;  // calls TRectangle.Draw
      Rectangle.Destroy;
    end;
      

  2.   

    Methods are by default static. When a static method is called, the declared (compile-time) type of the class or object variable used in the method call determines which implementation to activate. In the following example, the Draw methods are static.type
      TFigure = class
        procedure Draw;
      end;
      TRectangle = class(TFigure)
        procedure Draw;
      end;Given these declarations, the following code illustrates the effect of calling a static method. In the second call to Figure.Draw, the Figure variable references an object of class TRectangle, but the call invokes the implementation of Draw in TFigure, because the declared type of the 
    Figure variable is TFigure.var
      Figure: TFigure;
      Rectangle: TRectangle;
    begin
      Figure := TFigure.Create;
      Figure.Draw;  // calls TFigure.Draw
      Figure.Destroy;
      Figure := TRectangle.Create;
      Figure.Draw;  // calls TFigure.Draw
      TRectangle(Figure).Draw;  // calls TRectangle.Draw
      Figure.Destroy;
      Rectangle := TRectangle.Create;
      Rectangle.Draw;  // calls TRectangle.Draw
      Rectangle.Destroy;
    end;
      

  3.   

    delphi中的静态方法就是普通方法 有什么用就不用说了吧
    我想你问的肯定不是这个意思
      

  4.   

    delphi中的静态方法就是普通方法,和c++的静态方法不同,对应c++的静态方法在delphi中称为类方法(class function)