Yes, an event handler is basically a function reference. If you've ever used callbacks, this is basically the same idea. If not, here is a quick overview:
The type of event is defined as follows:
TZpOnNewTextEvent = procedure(const Sender: TObject; const aText: string) of object;
This means that this is a reference to a method of object with a signature that looks like this:
type TMyObject = class (TMyObjectAncestor) //stuff here procedure MyEventHandler(const Sender: TObject; const aText: string); //more stuff here end;
The bit of object important. This, in particular, is a reference to a method, and not a reference to an autonomous function.
For an event handler, you can configure the ExecuteConsoleApp method. This is almost the same as adding code to a button in the form designer. You put the button on the form, and then you assign the OnClick event handler, which sets up the button, adding the code that executes when the button is clicked. The difference is that here you do not have a form constructor to link it for you.
Fortunately, the syntax is pretty simple. For procedure (whatever) of object you pass an event handler just by specifying a name. Throw Self.MyEventHandler in the right place in the parameter list, and it will work.
Mason wheeler
source share