Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Learn C++ Event Handling In 5 Minutes

In this short tutorial, C++ Product Manager, David Millington, explains what event handlers are and how to use them in your C++ application development. 

Overview

Defining Event Handlers

In an event receiver class, such as your form, you define event handlers, which are simply methods that match the event handler type (return type, calling convention, and arguments) that match the event that they will handle. They are assignable like method pointers (since they are an object-oriented method pointer) to variables. Usually you do this in the Object Inspector, since events are heavily used for UI code: you will create an event handler (method) for (say) an OnClick event from the IDE, which will generate an empty method for you you can use to fill in the behaviour you want.

Code that handles events, ie sees something happen, just calls that method pointer to invoke your method.

Firing Events

To fire an event, simply check if the method pointer is null or not, and if not, call it. Usually you don’t need to worry about this: you define the methods and assign them, and existing library code, like a button class, looks after calling them.

Be sure to check out other tutorials on C++ Builder here:

Exit mobile version