gpt4 book ai didi

delphi - 如何声明数组属性?

转载 作者:行者123 更新时间:2023-12-03 14:40:41 24 4
gpt4 key购买 nike

我构建了类系统

  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是一个(私有(private))函数,它接受一个整数(Index)并返回相应的TFieldSpec,例如,

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

参见the documentation on array properties .

关于delphi - 如何声明数组属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12871142/

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