Am 17.04.2021 um 20:30 schrieb Ryan Joseph via fpc-pascal:
 From the documentation: "An abstract class is a class that cannot be instantiated 
directly. Instead, a descendent class must always be instantiated. However, for Delphi 
compatibility, the compiler ignores this directive."

Why does this get ignored and what does this have to do with Delphi? I 
personally would like for this to actually work and give a compiler error if 
you instantiate the abstract class.
The compiler will generate a warning in case you instantiate a class that is abstract or has abstract methods. You can escalate these warnings to errors if you need:

=== code begin ===

program tabstract;

{$MODE OBJFPC}
{$WARN CONSTRUCTING_ABSTRACT ERROR}

type
  TAbstract1 = class abstract
  end;

  TAbstract2 = class
    procedure Test; virtual; abstract;
  end;

var
  a1: TAbstract1;
  a2: TAbstract2;
begin
  a1 := TAbstract1.Create;
  a2 := TAbstract2.Create;
end.

=== code end ===

This will generate two (different) errors.

With this we're allowing more than Delphi does (which warns in the second case, but the warning can not be escalated to error and does not warn for the first case at all), but Delphi compatbility is more important here, thus the default is a warning and not an error. This will not be changed.

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to