加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 如何声明数组属性?

发布时间:2020-12-15 04:26:13 所属栏目:大数据 来源:网络整理
导读:我构建了类系统 TTableSpec=class(Tobject) private FName : string; FDescription : string; FCan_add : Boolean; FCan_edit : Boolean; FCan_delete : Boolean; FFields : array[1..100] of TFieldSpec; public property Name: String read FName; propert
我构建了类系统
TTableSpec=class(Tobject)
  private
    FName : string;
    FDescription : string;
    FCan_add : Boolean;
    FCan_edit : Boolean;
    FCan_delete : Boolean;
    FFields : array[1..100] of TFieldSpec;
  public
    property Name: String read FName;
    property Description: String read FDescription;
    property Can_add : Boolean read FCan_add;
    property Can_edit : Boolean read FCan_edit;
    property Can_delete : Boolean read FCan_delete;
    property Fields : array read FFields;
  end;

因此在TableSpec Fields属性将是字段列表(我使用TFieldSpec数组).如何组织字段列表(使用或不使用数组)作为编译的结果我收到一个错误

[Error] Objects.pas(97): Identifier expected but 'ARRAY' found
[Error] Objects.pas(97): READ or WRITE clause expected,but identifier 'FFields' found
[Error] Objects.pas(98): Type expected but 'END' found
[Hint] Objects.pas(90): Private symbol 'FFields' declared but never used
[Fatal Error] FirstTask.dpr(5): Could not compile used unit 'Objects.pas'

解决方法

你的行
property Fields : array read FFields;

是无效的语法.它应该是

property Fields[Index: Integer]: TFieldSpec read GetField;

其中GetField是一个(私有)函数,它使用一个整数(Index)并返回相应的TFieldSpec,例如,

function TTableSpec.GetField(Index: Integer): TFieldSpec;
begin
  result := FFields[Index];
end;

见the documentation on array properties.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读