繁体   English   中英

Delphi不兼容的类型

[英]Delphi incompatible types

我有一个非常奇怪的错误,我尝试重新启动我的IDE,但是并没有解决它。

我创建了一个界面,如下所示:

myInterface = interface
 ['{delphi guid key here}'] (CTRL+ALT+G)
 function getDataPCE : IDataPCE;
 property dataPCE : IDataPCE read getDataPCE;
 (some other properties that works)
end;

然后我创建了从该接口继承的对象

myObject = class(TInterfacedObject, myInterface)
 private
  ... 
  function getDataPCE : IDataPCE;
  ...
 public
  ...
  property dataPCE : IDataPCE read getDataPCE;
  ...
 end;

“ ...”表示还有一些其他属性和功能,但与此无关。

我收到此错误:“不兼容的类型”

我该如何解决?

编辑

    IInfoNotisReservation = interface
      ['{AE5CEC31-B2CE-4A3D-9CFE-6393646E4A04}']

      function getNumberPCE : String;
      function getDataPCE(numRegister : String; numPCEFormated : String): IRioPiece;
      procedure setNumberPCE(NumberPCE: String);
      function getRegName : String;
      procedure setRegName(RegName: String);
      function getRegKey : String;
      procedure setRegKey(RegKey: String);

      property NumberPCE : String read getNumberPCE write setNumberPCE;
      property RegName : String read getRegName write setRegName;
      property RegKey : String read getRegKey write setRegKey;
      property DataPCE : IRioPiece read getDataPCE;
    end;

type
  TInfoNotisReservation = class(TInterfacedObject, IInfoNotisReservation)

  private
    DataBase  : IDataBase;
    SuperRio  : ISuperRio;
    RioN      : IRio;
    fPCENum    : String;

    function getDataPCE(numRegister : String; numPCEFormated : String): IRioPiece;
    function getNumberPCE: string;
    function getRegKey: string;
    function getRegName: string;
    procedure setNumberPCE(NumberPCE: string);
    procedure setRegKey(RegKey: string);
    procedure setRegName(RegName: string);
    procedure setRioN(Registre: string);
  public
    Constructor Create;
    property DataPCE : IRioPiece read getDataPCE;
    property NumberPCE : String read getNumberPCE write setNumberPCE;
    property RegName : String read getRegName write setRegName;
    property RegKey : String read getRegKey write setRegKey;

end;

function TInfoNotisReservation.getDataPCE(numRegister,
  numPCEFormated: String): IRioPiece;
begin
  setRioN(numRegister);
  Result := RioN.GetPieceByID(RioN.PieceNumberToID(NumPCEFormated).Item[0].ID, FLAG_IGNORE_SECURITY);
end;

为了帮助您了解如何提出问题,以下是您应提交的MCVE。

type
  IRioPiece = interface
  end;

  IInfoNotisReservation = interface
    ['{AE5CEC31-B2CE-4A3D-9CFE-6393646E4A04}']
    function getDataPCE(numRegister: String; numPCEFormated: String): IRioPiece;
    property dataPCE: IRioPiece read getDataPCE; // ERROR HERE
  end;

begin
end.

这导致此错误:

[dcc32错误] E2008不兼容的类型

原因是类型IRioPiece的属性的属性IRioPiece必须是不接受任何参数且返回类型为IRioPiece 但是您的getter函数需要两个参数,它们需要来自某个地方。 如上所述,访问属性时不提供这些参数。

因此,您可以通过将getDataPCE的声明更改为getDataPCE来修复编译错误:

function getDataPCE: IRioPiece;

但这几乎肯定是错误的解决方案。 大概您getDataPCE这些参数声明为getDataPCE因为您需要提供它们。 在这种情况下,您将无法删除它们。 这意味着你不能声明一个简单的属性dataPCE由支持getDataPCE 我的猜测是,您只需要删除dataPCE属性。

当然,您可以这样声明一个数组属性

property dataPCE[numRegister: String; numPCEFormated: String]: IRioPiece 
  read getDataPCE;

这意味着您将按以下方式访问属性:

dataPCE := resvervation.dataPCE[numRegister, numPCEFormatted];

但是对我来说,这超出了财产的使用范围。 我认为最好使用一个函数来访问它。

结论

删除dataPCE属性,并让接口的getDataPCE代替。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM