blob: 7b4b285c616429395f4ada64e97e9e90823029a3 (
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
|
{ %fail }
{ %norun }
program WithForClassTypes;
{$IFDEF FPC}
{$mode delphi}
{$ENDIF}
type
TMyObject = class
x: Integer;
class procedure Foo; virtual;
procedure Bar; virtual;
end;
TMyObject2 = class(TMyObject)
class procedure Foo; override;
procedure Bar; override;
end;
TMyClass = class of TMyObject;
{ TMyObject }
procedure TMyObject.Bar;
begin
WriteLn('Bar ', Integer(Pointer(Self)),' ', x);
end;
class procedure TMyObject.Foo;
begin
WriteLn('Foo');
end;
{ TMyObject2 }
procedure TMyObject2.Bar;
begin
WriteLn('2Bar ', Integer(Pointer(Self)),' ', x);
end;
class procedure TMyObject2.Foo;
begin
WriteLn('2Foo');
end;
var
MyClass : TMyClass = TMyObject2;
begin
with MyClass do begin
Foo; // should work
with Create do try // should work
x := 3; // should work
Bar; // should work
finally
Free; // should work
end;
Foo; // should work
x := 1; // should not be allowed
// Bar; // should not be allowed
// Free; // should not be allowed
end;
end.
|