[fpc-pascal] FPC bug or brain bug ?

Yann Bat batyann811 at gmail.com
Thu May 27 16:01:08 CEST 2010


Hi,

I don't understand why compilation of the program below failed in fpc
and objfpc mode. In tp and delphi mode it works as expected but in fpc
and objfpc mode the compiler complains :

  blob.pas(17,3) Error: Constants of objects containing a VMT aren't allowed
  blob.pas(17,3) Fatal: Syntax error, ";" expected but "(" found

Since my object has no virtual methods why a VMT ?

Thanks.


{$mode fpc}
program Blob;

type
  TBlob = object
    private
      fId : LongInt;

    public
      constructor Init;
      function Id: LongInt;
  end;

  PBlob=^TBlob;

const
  NullBlob : TBlob = (fId: 0);

{=== TBlob ===}
constructor TBlob.Init;
begin
  fId:=Random(1024) + 1;
end;

function TBlob.Id;
begin
  Id:=fId;
end;

var
  B : TBlob;
begin
  B:=NullBlob;
  WriteLn('B : ', B.Id);

  B.Init;
  WriteLn('B : ', B.Id);
end.



More information about the fpc-pascal mailing list