tchlp89.pp 690 B

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