[fpc-pascal] static class methods

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Feb 6 22:10:46 CET 2008


On 06 Feb 2008, at 20:52, Jonathan Benedicto wrote:

> Why do static class methods in FPC have a "Self" parameter?  In  
> Delphi, static class methods do not have a Self parameter.

You need them to correctly handle cases like this:

***
{$ifdef fpc}
{$mode delphi}
{$endif}

type
   tc = class
     class procedure callme;
     class procedure test; virtual;
   end;

   td = class(tc)
     class procedure test; override;
   end;


class procedure tc.callme;
begin
   test;
end;

class procedure tc.test;
begin
   writeln('tc.test called, although td.test should be called');
end;

class procedure td.test;
begin
   writeln('td.test correctly called');
end;


var
   c: tc;
begin
   c:=td.create;
   c.callme;
   c.free;
end.

***

I'm not sure how Delphi could handle this without passing the VMT as  
invisible parameter (and from a cursory look at the code generated by  
Kylix, it does appear to pass the VMT).


Jonas



More information about the fpc-pascal mailing list