Function Pointer var



Function Pointer var
Smart pascal source code
type TVarProc = procedure(sender: TObject; var s: String); var proc: TVarProc; procedure Stuff(sender: TObject; var s: String); begin s := sender.ClassName; end; proc := Stuff; var s: String := 'hello'; var obj: TObject := TObject.Create; WriteLn(s); proc(obj, s); WriteLn(s); type TMyClass = class procedure Stuff(sender: TObject; var s: String); begin s := sender.ClassName + '!'; end; end; proc := TMyClass.Create.Stuff; proc(obj, s); WriteLn(s); proc(TMyClass.Create, s); WriteLn(s); {<<< RESULT - CONSOLE LOG >>> ----------------------------- hello TObject TObject! TMyClass! ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}