[fpc-pascal] Are there any drawbacks to "reference to"?

Anthony Walter sysrpl at gmail.com
Sun Jun 5 18:20:56 CEST 2022


As the "reference to" feature was recently added to fpc trunk, I'd like to
ask if internally there are any penalties (performance perhaps) or
drawbacks to using them in place of the more traditional "procedure" and
"procedure of object" types?

It's my understanding that for example using this code:

type
  TNotifyEvent = reference to procedure(Sender: TObject);
  // old version below
  // TNotifyEvent = procedure(Sender: TObject) of object;

Would allow BOTH methods and normal procedures to be assigned to fields or
variables of this redefined version of TNotifyEvent. The obvious benefit
would be that users could then have more options when assigning event
handlers, including anonymous procedures in addition to normal procedures
and methods.

If there are no drawbacks to using "reference to" (given that the compiler
someone is using is up to date with this feature), would it make sense
for everyone to start using it in place of l "procedure" and "procedure of
object" types? Obviously, when I say "procedure" in this question, I also
mean to include "function" as well.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20220605/9359efaa/attachment.htm>


More information about the fpc-pascal mailing list