我有消息不兼容的类型

时间:2016-04-21 12:01:14

标签: delphi

  TServiceData = class  
  strict private
    FPriority: Integer;
    ...
  public
    property Priority: Integer read FPriority write FPriority;
    ...
  end;

  TMonthData = class  
  strict private

    function GetServiceData(AIdx: Integer): TServiceData;
  public
    ...
    property ServiceData: TServiceData read GetlstServiceData;  // incompatible types - Why?
  end;

对不起。输入错误。原始

property ServiceData: TServiceData read GetServiceData; 

1 个答案:

答案 0 :(得分:2)

因为你在属性中没有参数。

property ServiceData: TServiceData read GetlstServiceData;

请参阅 - GetlstServiceData这里没有参数,因为Delphi无法从编译类型的唯一可用信息源中获取它们 - 非常property ServiceData: TServiceData声明。

您应该将参数添加到属性中,或者将其从函数中删除。

 TMonthData = class  
  strict private

    function GetValue0Args(): TServiceData;
    function GetValue1Arg(const AIdx: Integer): TServiceData;
    function GetValue2Args(const AIdx: Integer; const Flavour: string): TServiceData;
  public
    ...
    property Data0Args: TServiceData read GetValue0Args;  
    property Data1Arg[ SlotNumber: integer ]:  TServiceData read GetValue1Arg;  
    property Data2Args[ SNum: integer; Recipient: string ]:  TServiceData read GetValue2Args;  
  end;

参见所谓的"数组属性":http://docwiki.embarcadero.com/RADStudio/Seattle/en/Properties#Array_Properties

虽然"数组属性"实际上不是数组。该术语选择不当:数组永远不会将字符串或对象等复杂实体作为索引,而属性和函数会将它们作为可能的参数。