I frequently find myself declaring a simple procedure type
TMessageProc = procedure(const AMsg: String);
in Delphi. The purpose is to allow passing callback procedures to processing functions so that they can update the user interface without having to be aware of the user interface.
Surely this must be a common paradigm in Delphi programming. Does there exist an standard procedure type declaration in one of the commonly used units that I can use for this? Unfortunately, with the roll-my-own approach I’m not entirely consistent between projects in the way I name or declare the type.
The “common Delphi paradigm” is event (event handler). Eg, you can write
Normally the events in Delphi are implemented as methods, so the standard Delphi code for the above example is:
There is nothing wrong in declaring your personal event types, but sure you can find standard events in VCL. For example, classes.pas unit containes the declaration