Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-08

inline callback functions?

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryan Joseph

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

Reply by email