⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testrecords.out

📁 格式化源码的最新板
💻 OUT
字号:
unit TestRecords;

{ AFS 31 July 2K test record declarations

  This code compiles, but is not semantically meaningfull.
  It is test cases for the code-formating utility

  most of these defs are swiped from the delphi help on variant records }


interface

type

  TOneLineRec = record
    s1, s2: string;
    fiFred: integer;
  end;

  TLeftRec = record
    f1: integer;
    f2: string;
    f3: double;
  end;

  TLongRec = record
    l1:   TLeftRec;
    a:    string;
    b:    currency;
    c:    string;
    d:    currency;
    e:    string;
    f:    currency;
    fred: boolean;
    g:    string;
    h:    currency;
  end;


{ egs from the help, deformatted a bit }
type


  TDateRec = record
    Year:  integer;
    Month: (Jan, Feb, Mar, Apr, May, Jun,
      Jul, Aug, Sep, Oct, Nov, Dec);
    Day:   1..31;
  end;

  { missing final colons }
  TFooRec = record
    s1, s2: string
  end;

  TBarRec = record
    i1: integer
  end;

type

  TEmployee = record
    FirstName, LastName: string[40];
    BirthDate: TDateTime;
    case Salaried: boolean of
      True: (AnnualSalary: currency);
      False: (HourlyWage: currency);
  end;

  TPerson = record
    FirstName, LastName: string[40];
    BirthDate: TDateTime;
    case Citizen: boolean of
      True: (Birthplace: string[40]);
      False: (Country: string[20];
        EntryPort: string[20];
        EntryDate, ExitDate: TDateTime);
  end;


  { fields after the variant are not allowed, will not compile:
    "The variant part must follow the other fields in the record declaration"  }
  TFoo = record
    Bar: integer;
    case Spon: boolean of
      True: (Baz: PChar);
      False: (Wibble: integer;
        Fish: integer);
    // not allowed! liFred: integer;
  end;

  // nested records
  TFoo2 = record
    Bar: integer;
    case Spon: boolean of
      True: (Baz: PChar);
      False: (Fred: TFoo);
  end;

 { nested cases
  I don't know if there is a standard for these horrors, so I'll just be consistent
 }
  TFoo3 = record
    Bar: integer;
    case Spon: boolean of
      True: (Baz: PChar);
      False: (Fred: TFoo;
        case boolean of
          False: (liGoop: integer);
          True: (lcGlorp: currency);
        // comment here means next line cannot be brought up
      );
  end;

  TDeepNesting = record
    Bar: integer;
    case Spon1: boolean of
      True: (Baz1: PChar);
      False: (
        case Spon2: boolean of
          True: (Baz2: PChar);
          False: (
          case Spon3: boolean of
            True: (Baz3: PChar);
            False: (
            case Spon4: boolean of
              True: (Baz4: PChar);
              False: (
              case Spon5: boolean of
                True: (Baz5: PChar);
                False: (
                case Spon6: boolean of
                  True: (Baz6: PChar);
                  False: (liEndpoint: integer);
                );
              );
            );
          );
      );
  end;


implementation

type
  TImpRec = record
    s1, s2: string;
    fiFred: integer;
  end;

  TShapeList = (Rectangle, Triangle, Circle, Ellipse, Other);

  { in this case the variant is not tagged }
  TFigure = record
    liFoo: integer;
    case TShapeList of
      Rectangle: (Height, Width: real);
      Triangle: (Side1, Side2, Angle: real);
      Circle: (Radius: real);
      Ellipse, Other: ();
  end;


procedure HasComplexRecord;
type
  { try make sense of this !
    the things that we do for test cases }
  TLocalRec = record
    Foo: integer;
    Bar: (Trout, Mackrel, Rain, Earth);
    case Spon: boolean of
      True: (Baz: PChar);
      False: (Fred: TFoo;
        case boolean of
          False: (liGoop: integer);
          True: (lcGlorp: currency););
  end;
var
  lRec: TLocalRec;
begin
end;

procedure HasAnonRecordVar;
var
  { as before, only more fsck'd - a var with no type }
  lRec: record
    Foo: integer;
    Bar: (Trout, Mackrel, Rain, Earth);
    case Spon: boolean of
      True: (Baz: PChar);
      False: (Fred: TFoo;
        case boolean of
          False: (liGoop: integer);
          True: (lcGlorp: currency););
  end;

begin
end;

{ as above, but with several vars}
procedure HasAnonRecordVars2;
var
  li: integer;
  { as before, only more fsck'd - a var with no type }
  lRec1: record
    Foo: integer;
    Bar: (Trout, Mackrel, Rain, Earth);
  end;
  s2, s3, s4: string;
  lRec2: record
    Foo: integer;
    Bar: (Trout2, Mackrel2, Rain2, Mars);
    case Spon: boolean of
      True: (Baz: PChar);
      False: (Fred: TFoo);
  end;
  d1, d2, d3, d4: double;
  lRec: record
    Foo: integer;
    Bar: (Trout3, Mackrel3, Cloud, EarthPrime);
    case Spon: boolean of
      True: (Baz: PChar);
      False: (Fred: TFoo;
        case boolean of
          False: (liGoop: integer);
          True: (lcGlorp: currency););
  end;

  c1, c2, c3: currency;
begin
end;


end.

⌨️ 快捷键说明

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