Function Pointer default parameter



Function Pointer default parameter
Smart pascal source code
type TStringProc = procedure(s: String); procedure Test(s: String; f: TStringProc = nil); begin if Assigned(f) then f(s) else WriteLn(s); end; procedure WriteLnWrap(s: String); begin WriteLn('wrap: '); WriteLn(s); end; Test('Hello'); Test('World', nil); Test('Byebye', WriteLnWrap); Test('World', @WriteLnWrap); var p := @WriteLnWrap; Test('Hello', p); p := nil; Test('Again', p); {<<< RESULT - CONSOLE LOG >>> ----------------------------- Hello World wrap: Byebye wrap: World wrap: Hello Again ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}