1. Home
  2. Computing & Technology
  3. Delphi Programming

Class Method

By Zarko Gajic, About.com

Definition: A class method is a method that operates on classes instead of objects.

The definition of a class method must begin with the reserved word class.

The most common used class method in Delphi language is the "Create" constructor.

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 TCar, then Self is of the type class of TCar. 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.

Examples:
type
  TCar = Class
    //"object" method
    procedure Drive;
    //class method
    class procedure Stop;
  end;

  ...

  class procedure Stop;
  begin
   ...
  end;
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Getting Started with Delphi
  5. Delphi Programming Glossary
  6. Class Method - Glossary - Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.