[fpc-devel] Another question about class vars
Birger Jansen
birger at cnoc.nl
Thu Nov 4 12:58:41 CET 2010
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
More information about the fpc-devel
mailing list