简体   繁体   English

Delphi:类属性的错误2008年不兼容的类型

[英]Delphi: Error 2008 Incompatible types for a class property

I have this class defined 我定义了这个班

  TParamType = (ptDriverID, ptServer, ptHost, ptUser, ptPassword, ptPort, ptDatabase, ptOSAuth, ptPooled, ptUnicode);
  TDataType = (dtInteger, dtString, dtBoolean, dtYesNo, dtPassword);


  TParam = record
    Index: Byte;
    Typ: TParamType;
    RegKeyName: String;
    ConnName: String;
    DataType: TDataType;
    Caption: String;
    Value: String;
    Text: String;
    Default: String;
    Basic: Boolean;
    Enabled: Boolean;
    Mandatory: Boolean;
  end;

  TParams = class(TObject)
    private
      FParam: array of TParam;
      function GetParam(Index:Byte): TParam;
      procedure SetParam(Index:Byte;Value:String;Text:String);
    public
      constructor Create;
      destructor Destroy;
      property Param[Index: Byte]: TParam read GetParam write SetParam;
      procedure Enable(ServerType:TServerType);
  end;

I get this error: 'E2008 Incompatible types' to the code line 我收到此错误:代码行出现“ E2008不兼容类型”

property Param[Index: Byte]: TParam read GetParam write SetParam;

Any idea why I get this error for this property? 知道为什么我会为此属性收到此错误吗?

property Param is a TParam . property ParamTParam Therefore, SetParam needs to receive the Index into the array and a TParam to put there. 因此, SetParam需要将Index接收到数组中,并将TParam放入数组中。 Your setter instead provides the index and two strings, neither of which are a TParam . 相反,您的setter提供了索引和两个字符串,两个都不是TParam

The proper setter would be 合适的二传手是

procedure SetParam(Index: Byte; const Value: TParam);

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

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