Function Pointer ex05



Function Pointer example 05
Pas2JS pascal source code
type TMyFunc = function(i: Integer): String; type TMyClass = class FOffset: Integer; class function Conv(i: Integer): String; function DoConv(i: Integer): String; end; class function TMyClass.Conv(i: Integer): String; begin Result := '<' + IntToStr(i) + '> ' + ClassName; end; function TMyClass.DoConv(i: Integer): String; begin Result := '[' + IntToStr(i + FOffset) + ']'; end; function MyIntToStr(i: Integer): String; begin Result := '*' + IntToStr(i) + '*'; end; procedure WriteLnIt(f: TMyFunc; arg: Integer); begin WriteLn(f(arg)); end; var o := TMyClass.Create; o.FOffset := 5000; WriteLnIt(IntToStr, 123); WriteLnIt(MyIntToStr, 123); WriteLnIt(TMyClass.Conv, 123); WriteLnIt(o.DoConv, 123); var ff: TMyFunc; ff := IntToStr; WriteLnIt(ff, 456); ff := MyIntToStr; WriteLnIt(ff, 456); ff := TMyClass.Conv; WriteLnIt(ff, 456); ff := o.DoConv; WriteLnIt(ff, 456); {<<< RESULT - CONSOLE LOG >>> ----------------------------- 123 *123* <123> TMyClass [5123] 456 *456* <456> TMyClass [5456] ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}