Message methods that are declared with an integer constant can take only one var argument (typed or not):
Procedure TMyObject.MyHandler(Var Msg); Message 1; |
The TOBject.Dispatch method can be used to call a message handler. It is declared in the system unit and will accept a var parameter which must have at the first position a cardinal with the message ID that should be called. For example:
Type TMsg = Record MSGID : Cardinal Data : Pointer; Var Msg : TMSg; MyObject.Dispatch (Msg); |
If no such method is found, DefaultHandler is called. DefaultHandler is a virtual method of TObject that doesn’t do anything, but which can be overridden to provide any processing that might be needed. DefaultHandler is declared as follows:
procedure defaulthandler(var message);virtual; |
In addition to the message method with a Integer identifier, Free Pascal also supports a message method with a string identifier:
Procedure TMyObject.MyStrHandler(Var Msg); Message 'OnClick'; |
The working of the string message handler is the same as the ordinary integer message handler:
The TOBject.DispatchStr method can be used to call a message handler. It is declared in the system unit and will accept one parameter which must have at the first position a string with the message ID that should be called. For example:
Type TMsg = Record MsgStr : String[10]; // Arbitrary length up to 255 characters. Data : Pointer; Var Msg : TMSg; MyObject.DispatchStr (Msg); |
If no such method is found, DefaultHandlerStr is called. DefaultHandlerStr is a virtual method of TObject that doesn’t do anything, but which can be overridden to provide any processing that might be needed. DefaultHandlerStr is declared as follows:
procedure DefaultHandlerStr(var message);virtual; |
In addition to this mechanism, a string message method accepts a self parameter:
TMyObject.StrMsgHandler(Data : Pointer; Self : TMyObject);Message 'OnClick'; |
Remark: The type of the Self parameter must be of the same class as the class the method is defined in.