tchlp88.pp 586 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. { a helper of a parent class hides the parent's methods }
  2. program tchlp88;
  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. end;
  13. TFooHelper = class helper for TFoo
  14. function TestFoo: Integer;
  15. end;
  16. function TFoo.TestFoo: Integer;
  17. begin
  18. Result := 1;
  19. end;
  20. function TFooHelper.TestFoo: Integer;
  21. begin
  22. Result := 2;
  23. end;
  24. var
  25. b: TBar;
  26. res: Integer;
  27. begin
  28. b := TBar.Create;
  29. res := b.TestFoo;
  30. Writeln('b.TestFoo: ', res);
  31. if res <> 2 then
  32. Halt(1);
  33. Writeln('ok');
  34. end.