Name

Abstract Directive

Syntax

Virtual method declaration; abstract;

Description

The abstract directive applies to a virtual or dynamic method and means the method has no implementation. The compiler reserves a place in the virtual method table or assigns a dynamic method number. A derived class must provide an implementation for the abstract method. The abstract directive must follow the virtual, dynamic, or override directive.

Tips and Tricks

  • If a derived class does not override an abstract method, you can omit the method from the class declaration or declare the method with the override and abstract directives (in that order). The latter is preferable because it clearly documents the programmer’s intention not to implement the method, and does not leave the reader wondering whether the omission was deliberate or an oversight.

  • If you try to construct an object, and the compiler can tell that the class has abstract methods, the compiler issues a warning. Usually such a warning indicates one of two possible errors: (1) the programmer forgot to implement an abstract method in a derived class, or (2) you are trying to create an instance of a base class when you should be creating an instance of a derived class.

  • If you create an instance of the base class and call one of its abstract methods, Delphi calls the AbstractErrorProc procedure or generates runtime error 210 (EAbstractError).

See Also

AbstractErrorProc Variable, Class Keyword, Dynamic Directive, Override Directive, Virtual Directive ...

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.