Defines a proc called when an abstract method is called System unit
var AbstractErrorProc : Pointer;
The AbstractErrorProc variable defines to Delphi a procedure that it should call when your code erroneously calls an abstract method of a class.
Abstract methods are placeholder methods - only to be implemented by derived classes. The parent class is really a skeleton class, and therefore should not be instantiated into an object. delphi will warn you if you do. If you call an abstract method, it will call AbstractErrorProc before terminating with an error. If not found, it will throw EAbstractError exception instead.
You should normally avoid calling abstract methods.
Related commands
AbstractDefines a class method only implemented in subclasses
AddrGives the address of a variable, function or procedure
ProcedureDefines a subroutine that does not return a value
 Download this web site as a Windows program.

Example code : A polygon class with an abstract method called
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.

unit Unit1;


  Forms, Dialogs, Classes, Controls, StdCtrls, SysUtils;

  // Define a base TPolygon class :
  // This class is a traingle if 3 sides, square if 4 sides ...
  TPolygon = class
    sideCount  : Integer;  // How many sides?
    sideLength : Integer;  // How long each side?
    shapeArea  : Double;  // Area of the polygon
     procedure setArea; Virtual; Abstract;  // Cannot code until sides known
    property count  : Integer read sideCount;
    property length : Integer read sideLength;
    property area   : Double  read shapeArea;
    constructor Create(sides, length : Integer);

  // Define a square descendent
  TSquare = class(TPolygon)
    procedure setArea; override;  // Override the abstract method

  // Define the form class used by this unit
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    { Private declarations }
    { Public declarations }

  Form1: TForm1;

{$R *.dfm} // Include form definitions

// Create the TPolygon object
constructor TPolygon.Create(sides, length : Integer);
  // Save the number and length of the sides
  sideCount := sides;
  sideLength := length;

  // Set the area using the abstract setArea method :
  // This call will be satisfied only by a subclass

// Implement the abstract setArea parent method for the square
procedure TSquare.setArea;
  // Calculate and save the area of the square
  shapeArea := sideLength * sideLength;

procedure ReportAbstractError;
  // Report the error
  ShowMessage('ERROR : Abstract method called.');

// Main line code
procedure TForm1.FormCreate(Sender: TObject);
  square  : TSquare;
  polygon : TPolygon;
  // Set up a procedure to catch calls to abstract errors
  AbstractErrorProc := Addr(ReportAbstractError);

  // Create a square
  square  := TSquare.Create(4, 10);

  // Show the area of the square
  ShowMessageFmt('Square  area = %f',[square.area]);

  // Try to create a polygon (internally calls abstract method)
  polygon := TPolygon.Create(2, 10);  // Meaningless shape!

  // Show the area of the polygon
  ShowMessageFmt('Polygon area = %f',[polygon.area]);

  Square area = 100.0
  ERROR : Abstract method called.
  The program then terminates with an error dialog:
  Runtime error 210 at 00452208
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page