fpc/tests/webtbs/tw8150d.pp
Jonas Maebe 4e96fe8fac * fixed with-support for classrefdefs (mantis 8150), with thanks to
Thorsten Engler for supplying an initial patch

git-svn-id: trunk@6088 -
2007-01-20 20:04:54 +00:00

68 lines
1.0 KiB
ObjectPascal

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
if (x <> 3) then
halt(1);
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.