tfuncref50.pp 823 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. program tfuncref50;
  2. {$mode delphi}
  3. {$modeswitch functionreferences}
  4. type
  5. TFunc = reference to function(aArg: LongInt): LongInt;
  6. function Test(aArg: TFunc): LongInt;
  7. begin
  8. Result := aArg(42);
  9. end;
  10. type
  11. TTest = class
  12. function Method(aArg: String): LongInt; overload;
  13. function Method(aArg: LongInt): LongInt; overload;
  14. procedure DoTest;
  15. end;
  16. function TTest.Method(aArg: String): LongInt;
  17. begin
  18. Result := 1;
  19. end;
  20. function TTest.Method(aArg: LongInt): LongInt;
  21. begin
  22. Result := 2;
  23. end;
  24. procedure TTest.DoTest;
  25. begin
  26. Test(Method);
  27. end;
  28. function Func(aArg: String): LongInt; overload;
  29. begin
  30. Result := 1;
  31. end;
  32. function Func(aArg: LongInt): LongInt; overload;
  33. begin
  34. Result := 2;
  35. end;
  36. var
  37. t: TTest;
  38. begin
  39. t := TTest.Create;
  40. t.DoTest;
  41. t.Free;
  42. if Test(Func) <> 2 then
  43. Halt(2);
  44. end.