6

クラス TPerson があります。FSecondName は各オブジェクトに固有であることが知られています。

type
  TPerson = class(TObject)
  private
    FAge:        Integer;
    FFirstName:  String;
    FSecondName: String;
  public
    property Age:        Integer read FAge;
    property FirstName:  String  read FFirstName;
    property SecondName: String  read FSecondName;
    constructor Create;
  end;

クラス フィールド (C# の静的フィールドなど) を追加するにはどうすればよいですか。

ありがとう!

4

1 に答える 1

11

クラス変数を宣言できます。

type 
  TMyClass = class
  private
    class var
      FMyClassVar: Integer;
   end;

もちろん、クラス変数には好きな型を使用できます。

クラス変数にはグローバル ストレージがあります。したがって、変数の単一のインスタンスがあります。Delphi クラス変数は、C# の静的フィールドに直接似ています。

于 2013-08-09T11:17:37.720 に答える