summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/webtbs/tw8145.pp
blob: cdd5c18301c3b6e4385d6fe16142a23733bd5bb3 (plain)
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 ClassOfDifference;

{$IFDEF FPC}
  {$mode delphi}
{$ENDIF}

var
  l: longint;

type
  TMyObject = class
    class procedure Foo;
    class procedure Foo2; virtual;
  end;

  TMyClass = class of TMyObject;

  TMyDerivedObject = class(TMyObject)
    class procedure Foo2; override;
  end;

  TMyDerivedClass = class of TMyDerivedObject;


  TMyObject2 = class
    class procedure Foo3;
  end;
  TMyClass2 = class of TMyObject2;

  TMyDerivedObject2 = class(TMyObject2)
  end;
  TMyDerivedClass2 = class of TMyDerivedObject2;


class procedure TMyObject.Foo;
begin
  if (l <> 1) then
    halt(1);
end;

class procedure TMyObject.Foo2;
begin
  if (l <> 2) then
    halt(2);
end;


class procedure TMyDerivedObject.Foo2;
begin
  if (l <> 3) then
    halt(3);
end;


class procedure TMyObject2.Foo3;
begin
  if (l <> 4) then
    halt(4);
end;


var
  MyClassA : TMyClass = TMyObject;
  MyClassB : TMyClass = TMyDerivedObject;
  MyDerivedClass : TMyDerivedClass = TMyDerivedObject;

  MyClassA2 : TMyClass2 = TMyObject2;
  MyClassB2 : TMyClass2 = TMyDerivedObject2;
  MyDerivedClass2 : TMyDerivedClass2 = TMyDerivedObject2;

begin

  l := 1;
  TMyObject.Foo; //works in FPC and Delphi
  TMyDerivedObject.Foo; //works in FPC and Delphi

  MyClassA.Foo; //works in FPC and Delphi
  MyClassB.Foo; //works in FPC and Delphi
  MyDerivedClass.Foo; //works in FPC and Delphi
  TMyClass.Foo; //works only in Delphi
  TMyDerivedClass.Foo; //works only in Delphi

  l := 2;
  TMyObject.Foo2;
  MyClassA.Foo2;
  TMyClass.Foo2;

  l := 3;
  TMyDerivedObject.Foo2;
  TMyDerivedClass.Foo2;
  MyClassB.Foo2;


  l := 4;
  TMyObject2.Foo3; //works in FPC and Delphi
  TMyDerivedObject2.Foo3; //works in FPC and Delphi

  MyClassA2.Foo3; //works in FPC and Delphi
  MyClassB2.Foo3; //works in FPC and Delphi
  MyDerivedClass2.Foo3; //works in FPC and Delphi
  TMyClass2.Foo3; //works only in Delphi
  TMyDerivedClass2.Foo3; //works only in Delphi

end.