tgeneric115.pp 431 B

123456789101112131415161718192021222324252627282930
  1. {$Mode ObjFPC}{$H+}
  2. type
  3. TBase = class
  4. public
  5. function Foo:Integer;virtual;abstract;
  6. end;
  7. generic TTest<T:class> = class(T)
  8. public
  9. function Foo:Integer;override;
  10. end;
  11. generic TTest2<T:class> = class(specialize TTest<T>)
  12. public
  13. end;
  14. function TTest.Foo:Integer;
  15. begin
  16. Result:=42;
  17. end;
  18. var
  19. b: TBase;
  20. begin
  21. b:=specialize TTest2<TBase>.Create;
  22. if b.Foo<>42 then
  23. Halt(1);
  24. WriteLn('Ok');
  25. end.