[fpc-pascal] String message methods and the self parameter

Ewald ewald at yellowcouch.org
Sat Jan 6 17:19:54 CET 2018


Hi,

When reading https://www.freepascal.org/docs-html/ref/refsu31.html#x82-1040006.5.7 I stumbled on the following text at the bottom of the page:

"In addition to this mechanism, a string message method accepts a self parameter:
Procedure StrMsgHandler(Data: Pointer;  
                        Self: TMyObject); Message ’OnClick’;

When encountering such a method, the compiler will generate code that loads the Self parameter into the object instance pointer. The result of this is that it is possible to pass Self as a parameter to such a method.

Remark: The type of the Self parameter must be of the same class as the class the method is defined in."

1. This code snippet fails to compile with the message "Message handlers can take only one call by ref. parameter" (revision 30487, $mode objfpc)
2. "[...] When encountering such a method, [...]": What are the exact criteria: the parameter name, the parameter type, ...?
3. Can anybody explain what the part "The result of this is that it is possible to pass Self as a parameter to such a method." entails? How can it be passed with DispatchStr?
4. Can somebody give an example on how to use this functionality?

-- 
Ewald



More information about the fpc-pascal mailing list