如何声明数组属性? [英] How can I declare an array property?

查看:114
本文介绍了如何声明数组属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了课堂系统

  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数组).编译后如何组织字段列表(使用或不使用数组)

Thus in TableSpec Fields property shall be the list of fields (I used TFieldSpec array). How to organize the list of fields (using or without using an array) as as a result of compilation I receive an error

[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,例如

where GetField is a (private) function that takes an integer (the Index) and returns the corresponding TFieldSpec, e.g.,

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

请参见有关数组属性的文档.

这篇关于如何声明数组属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆