[fpc-pascal] inline callback functions?

Ryan Joseph ryan at thealchemistguild.com
Mon Aug 7 18:52:35 CEST 2017


I’m seeing feature this in other languages and it’s pretty useful. Has anyone ever considered this for Pascal?

Instead of declaring a method in the class (or other function) it’s written inline from the callers scope and inherits from that scope. The only advantage is readability since everything appears in one line and it’s cleaner since you don’t pollute the class with methods are only used in a single location and never called directly.

procedure TMyClass.FadeOut; 
var
	fadeAction: TSpriteAction;
begin
	fadeAction := TAction.ActionWithDuration(self, 2.0);
	fadeAction.SetEndedAction(@
		begin
			... // scoped in the calling class so "self" is available
		end;
	);
	fadeAction.FadeOut;
end;	

Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list