- What Is a Message?
- Types of Messages
- How the Windows Message System Works
- Delphi's Message System
- Handling Messages
- Sending Your Own Messages
- Nonstandard Messages
- Anatomy of a Message System: VCL
- The Relationship Between Messages and Events
- Summary
The Relationship Between Messages and Events
Now that you know all the ins and outs of messages, recall that this chapter began by stating that VCL encapsulates many Windows messages in its event system. Delphi's event system is designed to be an easy interface into Windows messages. Many VCL events have a direct correlation with WM_XXX Windows messages. Table 3.3 shows some common VCL events and the Windows message responsible for each event.
Table 3.3 VCL Events and Corresponding Windows Messages
VCL Event |
Windows Message |
OnActivate |
wm_Activate |
OnClick |
wm_XButtonDown |
OnCreate |
wm_Create |
OnDblClick |
wm_XButtonDblClick |
OnKeyDown |
wm_KeyDown |
OnKeyPress |
wm_Char |
OnKeyUp |
wm_KeyUp |
OnPaint |
WM_PAINT |
OnResize |
wm_Size |
OnTimer |
wm_Timer |
Table 3.3 is a good rule-of-thumb reference when you're looking for events that correspond directly to messages.
TIP
Never write a message handler when you can use a predefined event to do the same thing. Because of the contract-free nature of events, you'll have fewer problems handling events than you will handling messages.