File: fdt_typehelper.pas

package info (click to toggle)
lazarus 1.6.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 172,444 kB
  • ctags: 124,173
  • sloc: pascal: 1,528,777; xml: 260,232; sh: 3,008; java: 603; makefile: 512; perl: 297; sql: 222; ansic: 137
file content (114 lines) | stat: -rw-r--r-- 1,929 bytes parent folder | download | duplicates (8)
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
106
107
108
109
110
111
112
113
114
{
  ./testcodetools --format=plain --suite=TestFindDeclaration_TypeHelper
}
unit fdt_typehelper;

{$mode objfpc}{$H+}
{$ModeSwitch typehelpers}

interface

uses
  Classes, SysUtils;

type

  { TShortStringTypeHelper }

  TShortStringTypeHelper = type helper for ShortString
  public
    function MyVar: integer;
  end;

  { TStringTypeHelper }

  TStringTypeHelper = type helper for String
  public
    function Get45: integer;
  end;

  { TLongIntTypeHelper }

  TLongIntTypeHelper = type helper for LongInt
  public
    function GetStr: string;
  end;

  { TEnumTypeHelperOld }

  TEnumTypeHelperOld = type helper for TShiftStateEnum
  public
    function Old78: integer;
  end;

  { TEnumTypeHelper }

  TEnumTypeHelper = type helper(TEnumTypeHelperOld) for TShiftStateEnum
  public
    function Get78: integer;
  end;

procedure DoIt;

implementation

procedure DoIt;
var
  ShortS: ShortString;
  AnsiS: string;
  i: integer;
  e: TShiftStateEnum;
begin
  ShortS:='ABC';
  writeln('DoIt ',ShortS.MyVar{declaration:fdt_typehelper.TShortStringTypeHelper.MyVar});

  i:='Hello'.Get45{declaration:fdt_typehelper.TStringTypeHelper.Get45};
  if i<>45 then ;

  AnsiS:=i.GetStr{declaration:fdt_typehelper.TLongIntTypeHelper.GetStr};
  if AnsiS<>'' then ;

  e:=ssDouble;
  i:=e.Old78{declaration:fdt_typehelper.TEnumTypeHelperOld.Old78};
  if i<>78 then ;
  i:=e.Get78{declaration:fdt_typehelper.TEnumTypeHelper.Get78};
  if i<>78 then ;
end;

{ TEnumTypeHelperOld }

function TEnumTypeHelperOld.Old78: integer;
begin
  Result:=78;
end;

{ TEnumTypeHelper }

function TEnumTypeHelper.Get78: integer;
begin
  Result:=78;
end;

{ TLongIntTypeHelper }

function TLongIntTypeHelper.GetStr: string;
begin
  Result:=IntToStr(Self)
end;

{ TShortStringTypeHelper }

function TShortStringTypeHelper.MyVar: integer;
begin
  Result:=123;
end;

{ TStringTypeHelper }

function TStringTypeHelper.Get45: integer;
begin
  Result:=45;
end;

end.