我想知道我是否可以在一个类中创建一个记录数组,其中一些字段是只读属性,而其他字段则用于读写。
我可以想一个这样的例子:
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;
这里我们有一个客户数组,我想通过这个类的实例访问它…
我读到如何实现一个数组属性,我想知道我是否想有"ID"字段只读,而其他字段可读和写入
我认为你能得到的最接近的东西是这样的:
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;