Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-01

abstract classes

5 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Howard Page-Clark

FPC allows the Delphi-compatible "class abstract" syntax, but does not seem to prevent instantiation of such a class.
The following code compiles and runs satisfactorily (FPC version 2.6.0) Does trunk prevent this compiling?

program Project1;
{$mode objfpc}{$H+}
type
   TAbstractClass = class abstract
    class function GetID: integer; static;
   end;
class function TAbstractClass.GetID: integer;
begin
   Result:= 10;
end;
var
   ac: TAbstractClass;
begin
   ac:= TAbstractClass.Create;
   WriteLn(ac.GetID);
   ReadLn;
   ac.Free;
end.
Jonas Maebe
to Howard Page-Clark
Howard Page-Clark wrote
FPC allows the Delphi-compatible "class abstract" syntax, but does not seem to prevent instantiation of such a class. The following code compiles and runs satisfactorily (FPC version 2.6.0) Does trunk prevent this compiling?

No. Also see

Jonas

Leonardo M. Ramé
to Howard Page-Clark: FPC allows the Delphi-compatible "class abstract" syntax, but does not seem to prevent…
Show quoted text 34 lines
________________________________ From: Howard Page-Clark To: FPC users list Sent: Sunday, January 20, 2013 8:37 PM Subject: [fpc-pascal] abstract classes FPC allows the Delphi-compatible "class abstract" syntax, but does not seem to prevent instantiation of such a class. The following code compiles and runs satisfactorily (FPC version 2.6.0) Does trunk prevent this compiling? program Project1; {$mode objfpc}{$H+} type   TAbstractClass = class abstract    class function GetID: integer; static;   end; class function TAbstractClass.GetID: integer; begin   Result:= 10; end; var   ac: TAbstractClass; begin   ac:= TAbstractClass.Create;   WriteLn(ac.GetID);   ReadLn;   ac.Free; end.

As far as I remember Delphi has the same behavior.

Leonardo M. Ramé
http://leonardorame.blogspot.com

Graeme Geldenhuys
to Leonardo M. Ramé
Leonardo M. Ramé wrote
As far as I remember Delphi has the same behavior.

As I said in the other thread - it is a bug! Completely defeats the design principal of what "abstract class or method" means.

FPC should raise an error. I don't care what Delphi does - it's wrong.

Regards,
- Graeme -

Daniel Gaspary
to Graeme Geldenhuys
Graeme Geldenhuys wrote
As I said in the other thread - it is a bug! Completely defeats the design principal of what "abstract class or method" means. FPC should raise an error. I don't care what Delphi does - it's wrong.

I agree, it's awkward to just let the compiling proceed with code that can cause avoidable about letting this behavior as is ONLY for the delphi mode and abort compiling for objfpc ?