tchlp90.pp 796 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. { a helper of a parent class hides methods in the child class if its also a
  2. parent of the helper for the child class }
  3. program tchlp90;
  4. {$ifdef fpc}
  5. {$mode delphi}
  6. {$endif}
  7. {$apptype console}
  8. type
  9. TFoo = class
  10. function TestFoo: Integer;
  11. end;
  12. TBar = class(TFoo)
  13. function TestFoo: Integer;
  14. end;
  15. TFooHelper = class helper for TFoo
  16. function TestFoo: Integer;
  17. end;
  18. TBarHelper = class helper(TFooHelper) for TBar
  19. end;
  20. function TFoo.TestFoo: Integer;
  21. begin
  22. Result := 1;
  23. end;
  24. function TBar.TestFoo: Integer;
  25. begin
  26. Result := 4;
  27. end;
  28. function TFooHelper.TestFoo: Integer;
  29. begin
  30. Result := 2;
  31. end;
  32. var
  33. b: TBar;
  34. res: Integer;
  35. begin
  36. b := TBar.Create;
  37. res := b.TestFoo;
  38. Writeln('b.TestFoo: ', res);
  39. if res <> 2 then
  40. Halt(1);
  41. Writeln('ok');
  42. end.