Differences in calls of generic class functions in Delphi and Lazarus / FPC

Viewed 486

I have a project that should compile under Delphi and FPC, with generic class procedures. They compile to Delphi and FPC.

The calls to these procedures only compile to Delphi. To FPC, a specialization of the generic types must be given.

I want to omit this specializations in the calls, because there are maybe thousands of such calls to these procedures in the project. I would have to pick out the corresponding types for each call.

However, with specializations added in the calls, everything compiles in both directions.

// a simpified example of a generic class function

{$IFDEF FPC}{$MODE DELPHI}{$ENDIF} 
interface
type
   TMyClass = class
       class function MyFunc<A, B> ( bool : boolean;
                          var Data    : A;
                          var Key     : B): cardinal;
   end;
implementation

  class function TMyClass.MyFunc<A, B>(      bool : boolean;
                                      var Data    : A;
                                      var Key     : B): cardinal;
  begin
     // do something
  end;

procedure callGen;
var
  i : integer;
  s : string;
begin
   TMyClass.MyFunc(true,i, s);// compiles only to delphi
   TMyClass.MyFunc<integer, string>(true,i, s);// compiles in both directions
end; 

I want to omit the insertion of <integer, string> in the call, for in the project there are a huge number of of different types to insert and even more calls exist.

Error message in Lazarus for

TMyClass.MyFunc(true,i, s);

Fatal: Syntax error, ")" expected but "," found

0 Answers
Related