Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-11

Another question about class vars

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Birger Jansen

Hi all,

I am still a little confused about class vars and the difference there seems to be with how this behaves in Delphi. Take the following class:

  TMyClass = class
  private
    class var SomeClassVar: Integer;
  public
    SomeVar: Integer;
  end;

And two instances of this class: a,b: TMyClass

And let's do this:

  a.SomeClassVar := 10;
  b.SomeClassVar := 20;
  a.SomeVar := 30;
  b.SomeVar := 40;

I would expect this results:

a.SomeClassVar = 20
b.SomeClassVar = 20
a.SomeVar = 30
b.SomeVar = 40

But it turns out that for both a and b the value for SomeVar = 40. Which leads to the conclusion that SomeVar is also a class var. I would think that because of the new section (public) the declaration would default to 'var', but it doesn't. SomeVar is also added as a class var.

Changing the class to this...

  TMyClass = class
  private
    class var SomeClassVar: Integer;
  public
    var SomeVar: Integer;
  end;

(adding var to SomeVar)

...gives the expected result. I know this is probably not a bug, as was explained to me in my last post with a question related to class vars. But this minuscule difference between Delphi and FPC has a great impact (just spend 4 hours on tracking an issue down to this).

Any chance that this behaviour can be changed or is it just me who should be more carefull with this?

Kind regards,
Birger

Reply by email

Birger Jansen
to Paul Ishenin
04.11.2010 18:58, Birger Jansen wrote: > Any chance that this behaviour can be changed or is it just me who should be more carefull with this? You've found a bug. I will fix it later today.

Ok, that's great. I'll check the updates for this issue.

Kind regards,
Birger

Reply by email