123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- program tfuncref50;
- {$mode delphi}
- {$modeswitch functionreferences}
- type
- TFunc = reference to function(aArg: LongInt): LongInt;
- function Test(aArg: TFunc): LongInt;
- begin
- Result := aArg(42);
- end;
- type
- TTest = class
- function Method(aArg: String): LongInt; overload;
- function Method(aArg: LongInt): LongInt; overload;
- procedure DoTest;
- end;
- function TTest.Method(aArg: String): LongInt;
- begin
- Result := 1;
- end;
- function TTest.Method(aArg: LongInt): LongInt;
- begin
- Result := 2;
- end;
- procedure TTest.DoTest;
- begin
- Test(Method);
- end;
- function Func(aArg: String): LongInt; overload;
- begin
- Result := 1;
- end;
- function Func(aArg: LongInt): LongInt; overload;
- begin
- Result := 2;
- end;
- var
- t: TTest;
- begin
- t := TTest.Create;
- t.DoTest;
- t.Free;
- if Test(Func) <> 2 then
- Halt(2);
- end.
|