Delphi   发布时间:2022-04-11  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了delphi – 如何声明数组属性?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我构建了类系统
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是一个(私有)函数,它使用一个整数(IndeX)并返相应的TFieldSpec,例如,

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

the documentation on array properties.

大佬总结

以上是大佬教程为你收集整理的delphi – 如何声明数组属性?全部内容,希望文章能够帮你解决delphi – 如何声明数组属性?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。