11

クラスシステムを構築しました

  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'
4

2 に答える 2

27

あなたのライン

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;

配列のプロパティに関するドキュメントを参照してください。

于 2012-10-13T08:01:12.993 に答える
12

アンドレアスによって与えられたINDEXEDプロパティに関する答えは、ポスターが探している解決策であることに同意します。

完全を期すために、将来の訪問者のために、型に名前が付けられている限り、プロパティは配列型を持つことができることを指摘したいと思います。同じことがレコード、ポインタ、およびその他の派生型にも当てはまります。

type
  tMyColorIndex = ( Red, Blue, Green );
  tMyColor = array [ tMyColorIndex ] of byte;

  tMyThing = class
    private
      fColor : tMyColor;
    public
      property Color : tMyColor read fColor;
  end;
于 2012-10-14T11:03:33.043 に答える