File: recordsexample.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (105 lines) | stat: -rw-r--r-- 2,220 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
program RecordsExample;

{$mode objfpc}{$H+}
{$modeswitch advancedrecords} // {$mode delphi} has it automatically

uses
  Classes, SysUtils;

// advanced records
type
   LDT_ENTRY = record
           LimitLow : WORD;
           BaseLow : WORD;
           HighWord : record
               case longint of
                  0 : ( Bytes : record
                       BaseMid : BYTE;
                       Flags1 : BYTE;
                       Flags2 : BYTE;
                       BaseHi : BYTE;
                    end );
                  1 : ( Bits : record
                       flag0 : longint;
                    end );
               end;
        end;

  TRec1 = record
    hWnd : integer;
  private
    F1: Integer;
    F2: Byte;
  public
    type
      TBar = Integer;
    const
      C: TBar = 1;
    var
      F3: TBar;
      F4: Byte;
    class var
      F5: TBar;
  private
    type
      Int = Integer;
    var
      F: Int;
    const
      DefaultF: Int = 1;
  public
    function GetF: integer;
    procedure SetF(const Value: integer);
    // full list of operators see in tests/test/terecs6.pp
    class operator Inc(Rec: TRec1): TRec1;
  public
    case y: integer of
      0: (a: integer);
      1,2,3: (b: array[char] of char; c: char);
      3: ( d: record
                case byte of
                  10: (i: integer; );
                  11: (y: byte);
              end; );
      4: (e: integer;
            case byte of
            8: (f: integer)
          );
  end;

  tvardata = packed record
     vtype : tvartype;
     case integer of
        0:(res1 : word;
           case integer of
              0:
                (res2,res3 : word;
                 case word of
                    varstring : (vstring : pointer);
                    varany :  (vany : pointer);
               );
              1:
                (vlongs : array[0..2] of longint);
          );
        1:(vwords : array[0..6] of word);
        2:(vbytes : array[0..13] of byte);
     end;

function TRec1.GetF: integer;
begin
  Result := F;
end;

procedure TRec1.SetF(const Value: integer);
begin
  F := Value;
end;

class operator TRec1.Inc(Rec: TRec1): TRec1;
begin
  Result.F := Rec.F + 1;
end;

begin
end.