[fpc-pascal] class property accessor static
Maciej Izak
hnb.code at gmail.com
Tue Feb 7 12:30:26 CET 2017
2017-02-07 12:10 GMT+01:00 Mattias Gaertner <nc-gaertnma at netcologne.de>:
> The getter/setter of a class-property must be "static" (Delphi
> compatible).
> If I understand "static" correctly, then "static" simply omits passing
> the class as parameter. So a static class procedure is just a dumber
> version of a normal class procedure.
>
> What is the advantage of using "static" for class property accessors?
> Aka: Why did Delphi choose static here?
>
Generally "static" means no hidden parameter "self". "static" for methods
is used for methods designed for callbacks from external API.
We have 3 possibilities:
===code begin===
type
TFooClass = class of TFoo;
TFoo = class
function A: Int32; // self as instance
class function B: Int32; // self as meta class of TFoo
class function C: Int32; static; // no self
property D: Int32 read A;
property E: Int32 read B;
class property F: Int32 read C;
===code end===
"class property" has two advantages. First: you can use "static" methods
for properties and second: will work for improper implemented code ;)
(which is maybe disadvantage?):
TFoo($1).F;
TFooClass($1).F;
--
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170207/aa3766dc/attachment.html>
More information about the fpc-pascal
mailing list