[fpc-pascal] class property accessor static
Maciej Izak
hnb.code at gmail.com
Tue Feb 7 14:19:18 CET 2017
2017-02-07 13:51 GMT+01:00 Mattias Gaertner <nc-gaertnma at netcologne.de>:
> Why is that "more handy"? "static" does not have a Self. That
> is less handy, isn't it?
>
by "handy" I mean usage of "class properties" instead of "static methods".
> I can't follow you here. Are we still talking about why Delphi choose
> static instead of normal?
>
"class property" is used for code where class instance (nor assign to meta
class) is not needed. Some variance/idea of singleton pattern. TFoo might
be used as namespace:
===code begin===
var
Foo: TFooClass; // or Foo: TFoo
begin
WriteLn(Foo.F);
end;
===code end===
for regular "property" with "class methods" you need something like this:
===code begin===
var
Foo: TFooClass;
begin
Foo := TFoo;
WriteLn(Foo.E);
end;
===code end===
and for normal property:
===code begin===
var
Foo: TFoo;
begin
Foo := TFoo.Create;
WriteLn(Foo.D);
end;
===code end===
> True.
> OTOH you loose some possibilities.
>
True.
--
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170207/55e921ae/attachment.html>
More information about the fpc-pascal
mailing list