In Javascript, you can define an anonymous function that can be executed immediately. It is called an Immediate Invocation Function Expression, aka IIFE.
First, you declare the function, like so:
function () { console.log('Immediately invoked function execution'); }
Then, you wrap it up in ():
(function () { console.log('Immediately invoked function execution'); })
Finally, you add another () to execute it:
(function () { console.log('Immediately invoked function execution'); })()
In Delphi, similarly, you can define an anonymous method:
procedure begin WriteLn('Hello world'); end
Then, you wrap it up with ():
(procedure begin WriteLn('Hello world'); end)
And finally, execute it!
(procedure begin WriteLn('Hello world'); end)();
Here's another example:
WriteLn((function (const X: string): Boolean begin WriteLn(X); Result := True; end)('Hello'));
The output for this shows the following x:
HelloTRUE
In 2017, with the release of Delphi 10.2 Tokyo, Embarcadero introduced a specialized implementation of the Observer pattern into the System.Classes unit. While it has been in the wild for 9 years, it remains a "hidden" architecture for many, primarily because it serves as the invisible engine behind LiveBindings. Other than live bindings, you can also use the Observer pattern as a way to update component settings to the Windows registry, an .ini file, or persist it elsewhere.
System.Classes