Forum > General

class variables and static fields

(1/2) > >>

Zoran:
Since FPC 2.6 class fields can be declared this way (as documented in this wiki page):

--- Code: ---type
  TSomeClass = class
  public
    class var
      FSomeClassVar: TSomeType;
  end;

--- End code ---

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:

--- Quote ---are there any differences between these two? Are these static fields and class vars actually same thing?
--- End quote ---
http://docwiki.embarcadero.com/RADStudio/XE5/en/Methods#Class_Static_Methods

Zoran:

--- Quote from: Leledumbo on February 21, 2014, 11:58:22 pm ---
--- Quote ---are there any differences between these two? Are these static fields and class vars actually same thing?
--- End quote ---
http://docwiki.embarcadero.com/RADStudio/XE5/en/Methods#Class_Static_Methods

--- End quote ---

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:

--- Quote from: Zoran on February 21, 2014, 03:59:04 pm ---My question is - ... Are these static fields and class vars actually same thing?

--- End quote ---
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 }

--- End quote ---

Zoran:
Thank you, so these are same.

Navigation

[0] Message Index

[#] Next page

Go to full version