Function Pointer ex04



Function Pointer example 04
Smart pascal source code
type TMyFunc = procedure(v: Variant); procedure WriteLn2(str: Variant); begin asm if (window.console) { window.console.log(@str); }; end; end; var f: TMyFunc := WriteLn2; f('hello '); f := WriteLn2; f('world'); function MyWriteLn(b: Boolean): TMyFunc; begin if b then Result := WriteLn2 else Result := WriteLn2; end; MyWriteLn(True)('Line Feed'); MyWriteLn(False)('No'); MyWriteLn(False)('Line Feed'); var a: array [0 .. 1] of TMyFunc; a[0] := WriteLn2; a[1] := WriteLn2; a[1]('!'); a[0]('No'); a[0]('Line Feed'); a[1]('Line Feed'); {<<< RESULT - CONSOLE LOG >>> ----------------------------- hello world Line Feed NoLine Feed! NoLine FeedLine Feed ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}