testproperties.out

来自「格式化源码的最新板」· OUT 代码 · 共 115 行

OUT
115
字号
unit TestProperties;


{ AFS 9 July 2K
 This unit compiles but is not semantically meaningfull
 it is test cases for the code formatting utility

  Test bug reported by  Michael Hieke in properties
  and some other property permutations
}

interface

uses Types;

type
  TFoo = class(TObject)
  private
    fiBar, fiBaz, fiWibble, fiFish, fiQuux: integer;

    function GetArray(piIndex: integer): integer;
    procedure SetArray(piIndex: integer; piValue: integer);

    function GetConstArray(const piIndex: integer): integer;
    procedure SetConstArray(const piIndex: integer; piValue: integer);
    function GetComplexArrayProp(const piIndex: integer;
      var pcString: string): boolean;


  public

    property ArrayVal[piIndex: integer]: integer Read GetArray Write SetArray; default;
    property ConstArrayVal[const piIndex: integer]: integer
      Read GetConstArray Write SetConstArray;

    property ComplexArrayProp[const piIndex: integer;
      var pcsString: string]: boolean Read GetComplexArrayProp;

  published
    { properties, plain to complex}
    property Bar: integer Read fiBar Write fiBar;
    property Baz: integer index 3 Read fiBaz Write fiBaz;
    property Wibble: integer Read fiWibble Write fiWibble stored False;
    property Fish: integer index 5 Read fiFish Write fiFish default 6;
    property Quux: integer index 5 Read fiQuux Write fiQuux nodefault;

  end;

type
  TBar = class(TObject)

    function GetArray(piIndex: integer): integer;
    procedure SetArray(piIndex: integer; piValue: integer);

  public
    property ArrayVal[piIndex: integer]: integer Read GetArray Write SetArray; default;

  end;

type

  THasAPoint = class(TObject)
  private
    FPoint: TPoint;
  public
    property X: integer Read FPoint.x;
    property Y: integer Read FPoint.y Write FPoint.y;
  end;


implementation

{ TFoo }

function TFoo.GetArray(piIndex: integer): integer;
begin
  Result := piIndex * 3;
end;

function TFoo.GetComplexArrayProp(const piIndex: integer;
  var pcString: string): boolean;
begin
  Result   := False;
  pcString := pcString + 'aa';
end;

function TFoo.GetConstArray(const piIndex: integer): integer;
begin
  Result := piIndex * 3;
end;

procedure TFoo.SetArray(piIndex, piValue: integer);
begin
  // do nothing
end;

procedure TFoo.SetConstArray(const piIndex: integer; piValue: integer);
begin
  // do nothing
end;

{ TBar }

function TBar.GetArray(piIndex: integer): integer;
begin
  Result := piIndex * 4;
end;

procedure TBar.SetArray(piIndex, piValue: integer);
begin
  // do nothing
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?