Abstract Directive
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.
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 AbstractErrorPro
c
procedure or generates runtime error 210
(EAbstractError
).
AbstractErrorProc Variable, Class Keyword, Dynamic Directive, Override Directive, Virtual Directive |