Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-01

String message methods and the self parameter

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ewald

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
Sven Barth
to Ewald

Am 06.01.2018 17:25 schrieb "Ewald" :

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

Ewald
to Sven Barth
Sven Barth 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