Quote Originally Posted by chronozphere
Hey guys

I learned java programming (because I had to, university) and one thing I really liked about the language is that you could create static variables and methods. These are not associated to individual objects but with the class as a whole.

Does someone know which version of Delphi (and up) supports this? And what about FPC?

I'd like to use this, but because I want to keep my code Delphi and FPC compatible, I'm not sure if this will be possible. Does anyone know more 'bout this?

Thanks
I'm slightly confused by your limited description, so I'll give you an example unit for demonstrating what I know and hope I cover what you desire:

[pascal]
unit Unit2;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils;

type
TMO = class
public
peach: integer;
procedure test();
private
pear: integer;
end;

var
orange: integer;

implementation

var
apple: integer;

procedure TMO.test();
begin
apple := 777;
orange := 888;
peach := 999;
pear := 000;
end;

end.
[/pascal]
Now lets assume you have another unit (unit1) that uses unit2 and has an object of TMO.
unit2.apple is undefined; declaring it after implementation makes it local to unit2 only.
unit2.orange is global/public, so you can access it.
TMO.test(); sets the local variable apple, but unless you make a getter, you cannot access apple.
TMO.peach is public, so you can access it.
TMO.pear is private, so you cannot.

Now, I do have a limited java experience, but I never used static variables or methods, so I don't have much of a basis for what you are saying or meaning by "available to the whole class".

Based on my googling, it appears to be a global variable that is not reset upon each instantiation of a class, but instead keeps its value. Handy.

What you have to remember between pascal and java, is that in Pascal a unit is not an object. In java, a class is usually an object or contains multiple classes, so multiple objects.

In this case, I believe what you're looking for is the variable "apple" in my example; you set it, and every instance of TMO can access and change the same variable.

Also using FPC 2.2.X, if you couldn't guess by the {$mode objfpc}