gpt4 book ai didi

arrays - 在类内对记录数组的字段实现属性读取和读写

转载 作者:行者123 更新时间:2023-12-03 18:36:44 25 4
gpt4 key购买 nike

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

我可以想到这样的例子:

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;


在这里,我们有一系列客户,我希望可以通过此类的实例进行访问...

我阅读了有关如何实现 array property的信息,并且想知道我是否希望将“ 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;

关于arrays - 在类内对记录数组的字段实现属性读取和读写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22432055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com