class variables and static fields lazarus / 62-General ---------------------------------------------------------------------- Zoran · 2014-02-21 14:59 Since FPC 2.6 class fields can be declared this way (as documented in this wiki page): Code: [Select]type   TSomeClass = class   public     class var       FSomeClassVar: TSomeType;   end; In this example variable FSomeClassVar is allocated globally (just one variable exists per class, not per class instance), and it can be accessed through class name (TSomeClass.FSomeClassVar). In fpc documentation, I didn't find anything about these class variables. However, in Reference guide, I found about static fields. Although Reference guide mentions these in chapter about old tp style objects, I tried and this syntax works in classes. My question is - are there any differences between these two? Are these static fields and class vars actually same thing? ---------------------------------------------------------------------- Leledumbo · 2014-02-21 22:58 Quoteare there any differences between these two? Are these static fields and class vars actually same thing?http://docwiki.embarcadero.c om/RADStudio/XE5/en/Methods#Class_Static_Methods ---------------------------------------------------------------------- Zoran · 2014-02-21 23:34 Quote from: Leledumbo on February 21, 2014, 11:58:22 pmQuoteare there any differences between these two? Are these static fields and class vars actually same thing?http://docwiki.embarcadero.com/RADStudio/XE5/ en/Methods#Class_Static_Methods Thanks, Leledumbo, for trying to help, but this link says nothing about what I asked. It doesn't even talk about fields, but about methods. However, starting from your link, I jumped to the article about fields, where class fields in Delphi are mentioned. Still, there is nothing about static fields, so my question is still without answer. ---------------------------------------------------------------------- engkin · 2014-02-22 01:36 Quote from: Zoran on February 21, 2014, 03:59:04 pmMy question is - ... Are these static fields and class vars actually same thing? Yes. Based on a comment in the source code, class var is a section where all fields inside it are static, while static directive is used for one single field. Quote from: compiler\pdecvar.pas    procedure read_record_fields(options:Tvar_dec_options; reorderlist: TFPObjectList; variantdesc : ppvariantrecdesc); ...                  { if it is not a class var section and token=STATIC then it is a class field too } ---------------------------------------------------------------------- Zoran · 2014-02-26 07:51 Thank you, so these are same. ---------------------------------------------------------------------- BigChimp · 2014-02-26 09:00 @Zoran/anyone: please feel free to raise a bug against documentation/fpdoc on the bugtracker pointing out the missing documentation. Doc bugs are almost always resolved, though it may take some time... ---------------------------------------------------------------------- Zoran · 2014-02-26 10:35 Quote from: BigChimp on February 26, 2014, 10:00:12 am@Zoran/anyone: please feel free to raise a bug against documentation/fpdoc on the bugtracker pointing out the missing documentation. Doc bugs are almost always resolved, though it may take some time... Okay, here it is: http://bugs.freepascal.org/view.php?id=25786 ---------------------------------------------------------------------- BigChimp · 2014-02-26 10:51 Thanks a lot!