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 E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...