RAD Studio (Common)
ContentsIndex
PreviousUpNext
x1020: Constructing instance of '%s' containing abstract method '%s.%s' (Delphi)

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

program Produce;
(*$WARNINGS ON*)
(*$HINTS 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 'b' created here would cause a runtime error. A hint will be issued that the value assigned to 'b' is never used.

program Solve;
(*$WARNINGS ON*)
(*$HINTS ON*)

  type
    Base = class
      procedure Abstraction; virtual;
    end;

  var
    b : Base;

  procedure Base.Abstraction;
  begin
  end;

begin
  b := Base.Create;
end.

One solution to this problem is to remove the abstract directive from the procedure declaration, as is shown here. Another method of approaching the problem would be to derive a class from Base and then provide a concrete version of Abstraction. A hint will be issued that the value assigned to 'b' is never used.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!