HomeDelphiDelphi Error – X1020 Constructing instance of ‘%s’ containing abstract method ‘%s.%s’

Delphi Error – X1020 Constructing instance of ‘%s’ containing abstract method ‘%s.%s’

Delphi Compiler Error

X1020 Constructing instance of ‘%s’ containing abstract method ‘%s.%s’

Reason for the Error & Solution

The identifier for the directive: CONSTRUCTING_ABSTRACT

The code you are compiling is constructing instances of classes which contain abstract methods.

program Produce;
{$WARNINGS ON}
{$WARN CONSTRUCTING_ABSTRACT ON}

  type
    Base = class
      procedure Abstraction; virtual; abstract;
    end;

  var
    b : Base;

begin
  b := Base.Create;
end.

An abstract procedure does not exist, so it becomes dangerous to create instances of a class which contains abstract procedures. In this case, the creation of ‘b’ is the cause of the warning. Any invocation of ‘Abstraction’ through the instance of ‘Base’ created here would cause a runtime error.

One solution to this problem is to remove the abstract directive from the procedure declaration, as is shown in the following example:

program Solve;

  type
    Base = class
      procedure Abstraction; virtual;
    end;

  var
    b : Base;

  procedure Base.Abstraction;
  begin
  end;
 
begin
  b := Base.Create;
end.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...