[next] [prev] [prev-tail] [tail] [up]

### 5.3 Static fields

When the {$STATIC ON} directive is active, then an object can contain static fields: these fields are global to the object type, and act like global variables, but are known only as part of the object. They can be referenced from within the objects methods, but can also be referenced from outside the object by providing the fully qualified name.

For instance, the output of the following program:

{$static on}
type
cl=object
l : longint;static;
end;
var
cl1,cl2 : cl;
begin
cl1.l:=2;
writeln(cl2.l);
cl2.l:=3;
writeln(cl1.l);
Writeln(cl.l);
end.

will be the following

2
3
3

Note that the last line of code references the object type itself (cl), and not an instance of the object (cl1 or cl2).

[next] [prev] [prev-tail] [front] [up]