thlp45.pp 827 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. { this tests that the correct method is called if a helper overloads an
  2. existing function and calls the original one recursively }
  3. program thlp45;
  4. {$mode objfpc}{$H+}
  5. type
  6. TTest = class
  7. function Test(aRecurse: Boolean; aTest: String): Integer;
  8. end;
  9. TTestHelper = class helper for TTest
  10. function Test(aRecurse: Boolean; aTest: array of String): Integer; overload;
  11. end;
  12. function TTest.Test(aRecurse: Boolean; aTest: String): Integer;
  13. begin
  14. Result := 1;
  15. end;
  16. function TTestHelper.Test(aRecurse: Boolean; aTest: array of String): Integer;
  17. begin
  18. if aRecurse then
  19. Result := Test(False, aTest[0])
  20. else
  21. Result := 2;
  22. end;
  23. var
  24. t: TTest;
  25. res: Integer;
  26. begin
  27. t := TTest.Create;
  28. res := t.Test(True, ['Test']);
  29. Writeln('t.Test: ', res);
  30. if res <> 1 then
  31. Halt(1);
  32. Writeln('ok');
  33. end.