String message methods and the self parameter

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

String message methods and the self parameter

Ewald-2
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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: String message methods and the self parameter

Free Pascal - General mailing list
Am 06.01.2018 17:25 schrieb "Ewald" <[hidden email]>:
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?

Judging from the implementation inside the RTL I'd say that this is a bug in the documentation. String message methods work like ordinal ones and take only one parameter. 

Regards, 
Sven 


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: String message methods and the self parameter

Ewald-2
On 06/01/18 17:35, Sven Barth via fpc-pascal wrote:
> Judging from the implementation inside the RTL I'd say that this is a
> bug in the documentation. String message methods work like ordinal
> ones and take only one parameter.

Yes, that is what it seems like. So once upon a time this feature was present, probably while the syntax was still "data: pointer" instead of "var data"?

Anyway, I'll file a bug against the documentation in a couple of days or so.

--
Ewald
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal