Message handlers

Top  Previous  Next

What is translated > Message handlers

 

Message handlers are methods that implement responses to dynamically dispatched messages. Delphi’s VCL uses message handlers to respond to Windows messages.

 

In Delphi a message handler is created by including the message directive in a method declaration, followed by an integer constant between 1 and 49151 which specifies the message ID.

 

In CBuilder the routine for handling the message can be declared as a macro:

 

#define VCL_MESSAGE_HANDLER(msg,type,meth)          \

 

          case    msg:                              \

            meth(*((type *)Message));               \

            break;

 

This macros has to be embedded in two other macros:

 

#define BEGIN_MESSAGE_MAP virtual void __fastcall Dispatch(void *Message) \

 

        {                                           \

          switch  (((PMessage)Message)->Msg)        \

          {

 

 

#define END_MESSAGE_MAP(base)    default:    \

 

                        base::Dispatch(Message);\

                        break;                  \

          }                                     \

        }

 

 

For example the two message handlers:

 

  procedure WMVScroll(var Message: TWMVScroll); 

                      Message WM_VSCROLL;

  procedure WMHScroll(var Message: TWMHScroll); 

                      Message WM_HSCROLL;

 

 

are translated to CBuilder C++:

 

  MESSAGE void __fastcall WMVScroll( TWMVScroll& Message ) 

               /*# WM_VSCROLL */;

  MESSAGE void __fastcall WMHScroll( TWMHScroll& Message ) 

               /*# WM_HSCROLL */;

 

 

  BEGIN_MESSAGE_MAP

    VCL_MESSAGE_HANDLER(WM_VSCROLL, TWMVScroll, WMVScroll)

    VCL_MESSAGE_HANDLER(WM_HSCROLL, TWMHScroll, WMHScroll)

  END_MESSAGE_MAP( TPanel )

 

If the CBuilder option is not set, only the comments are written, but not the macros.

 

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content