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:Originally Posted by chronozphere
[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}
Bookmarks