Arrays 实现属性读取和读取&;在类内为记录数组的字段编写

Arrays 实现属性读取和读取&;在类内为记录数组的字段编写,arrays,class,delphi,properties,records,Arrays,Class,Delphi,Properties,Records,我想知道我是否可以在一个类中创建一个记录数组,其中一些字段是只读属性,而另一些字段是可读写的 我可以举一个这样的例子: unit clsCustomers; interface uses Classes; type TUnitsCategory = (type1, type2, type3, type4); TCustomer = record ID : LongWord; name : string[25]; surname

我想知道我是否可以在一个类中创建一个记录数组,其中一些字段是只读属性,而另一些字段是可读写的

我可以举一个这样的例子:

unit clsCustomers;

interface

uses
  Classes;

type

  TUnitsCategory = (type1, type2, type3, type4);

  TCustomer = record
    ID       : LongWord;
    name     : string[25];
    surname  : string[25];
    category : TUnitsCategory;
  end;
  TCustomers = array of TCustomer;

  CCustomers = class
    private
      mycustomers : TCustomers;
    protected
    ...
    published
      property customer[index: LongWord]: TCustomers           //
        read mycustomer[index].ID;                             // <-- just to say...
        read mycustomer[index].name  write mycustomer[index].name; // 

  end;
CCustomers = class
private
  mycustomers : TCustomers;
public
  property customerID[index: LongWord]: LongWord read mycustomers[index].ID;                            
  property customerName[index: LongWord] read mycustomers[index].name write mycustomers[index].name;
  ...
end;
unitclscustomers;
接口
使用
班级;
类型
突尼斯分类=(类型1、类型2、类型3、类型4);
t客户=记录
ID:长单词;
名称:字符串[25];
姓氏:string[25];
类别:突尼斯分类;
结束;
TCustomers=TCustomer的数组;
类
私有的
我的客户:T客户;
受保护的
...
出版
物业客户[索引:LongWord]:t客户//

读取mycustomer[index].ID;// 我认为你能得到的最接近的东西是这样的:

unit clsCustomers;

interface

uses
  Classes;

type

  TUnitsCategory = (type1, type2, type3, type4);

  TCustomer = record
    ID       : LongWord;
    name     : string[25];
    surname  : string[25];
    category : TUnitsCategory;
  end;
  TCustomers = array of TCustomer;

  CCustomers = class
    private
      mycustomers : TCustomers;
    protected
    ...
    published
      property customer[index: LongWord]: TCustomers           //
        read mycustomer[index].ID;                             // <-- just to say...
        read mycustomer[index].name  write mycustomer[index].name; // 

  end;
CCustomers = class
private
  mycustomers : TCustomers;
public
  property customerID[index: LongWord]: LongWord read mycustomers[index].ID;                            
  property customerName[index: LongWord] read mycustomers[index].name write mycustomers[index].name;
  ...
end;

谢谢你的回答。我得到了这个错误:“[dcc32 error]clsCustomers.pas(26):E2188发布的属性'customerID'不能是数组类型”抱歉,它需要是公共的。如果需要设计时访问,请使用TCollection。