Static Methods

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.


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


Figure: TFigure; Rectangle: TRectangle;


Figure := TFigure.Create;

  1. Draw; // calls TFigure.Draw
  2. Destroy;

Figure := TRectangle.Create;


// calls TFigure.Draw

TRectangle(Figure).Draw; // calls TRectangle.Draw Figure.Destroy;

Rectangle := TRectangle.Create;

  1. Draw; // calls TRectangle.Draw
  2. Destroy;


Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment