Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi和Lazarus/FPC中泛型类函数调用的差异_Delphi_Lazarus_Freepascal - Fatal编程技术网

Delphi和Lazarus/FPC中泛型类函数调用的差异

Delphi和Lazarus/FPC中泛型类函数调用的差异,delphi,lazarus,freepascal,Delphi,Lazarus,Freepascal,我有一个项目,应该在Delphi和FPC下编译,带有通用类过程。它们编译成Delphi和FPC 对这些过程的调用只编译为Delphi。对于FPC,必须给出泛型类型的专门化 我想在调用中省略这个专门化,因为在项目中可能有数千个这样的过程调用。我必须为每个电话选择相应的类型 但是,通过在调用中添加专门化,所有内容都可以双向编译 //泛型类函数的简化示例 {$IFDEF FPC}{$MODE DELPHI}{$ENDIF} interface type TMyClass = class

我有一个项目,应该在Delphi和FPC下编译,带有通用类过程。它们编译成Delphi和FPC

对这些过程的调用只编译为Delphi。对于FPC,必须给出泛型类型的专门化

我想在调用中省略这个专门化,因为在项目中可能有数千个这样的过程调用。我必须为每个电话选择相应的类型

但是,通过在调用中添加专门化,所有内容都可以双向编译

//泛型类函数的简化示例

{$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; 
致命:语法错误,应为“”,但找到“”


看起来fpc编译器在这里不进行类型推断。提交功能请求。
TMyClass.MyFunc(true,i, s);