With Laz 2.0.6 and FPC 3.0.4 the following program
program CustomFunction;
{$mode objfpc}{$H+}
type
TCustomFunc = function(AValue: Integer): Integer;
TMyObject = class
public
class var
p1, p2: Integer;
class function GetAFunction(param1, param2: Integer): TCustomFunc;
end;
function Param100OrMore(aValue: Integer): Integer;
begin
Result := (TMyObject.p2 * 10) + (AValue * 10) - TMyObject.p1;
end;
function Param100Less(aValue: Integer): Integer;
begin
Result := TMyObject.p1 + AValue * 10 - TMyObject.p2;
end;
class function TMyObject.GetAFunction(param1, param2: Integer): TCustomFunc;
begin
p1 := param1;
p2 := param2;
case (param1 < 100) of
True: Exit(@Param100Less);
False: Exit(@Param100OrMore);
end;
end;
begin
WriteLn('param1 = 10, param2 = 1, aValue = 2, result = ',TMyObject.GetAFunction(10, 1)(2));
WriteLn('param1 = 100, param2 = 1, aValue = 2, result = ',TMyObject.GetAFunction(100, 1)(2));
end.
outputs this:
param1 = 10, param2 = 1, aValue = 2, result = 29
param1 = 100, param2 = 1, aValue = 2, result = -70